diff options
-rw-r--r-- | parse-events.c | 61 | ||||
-rw-r--r-- | trace-input.c | 8 | ||||
-rw-r--r-- | trace-read.c | 2 |
3 files changed, 39 insertions, 32 deletions
diff --git a/parse-events.c b/parse-events.c index 9bbb401..01588c5 100644 --- a/parse-events.c +++ b/parse-events.c | |||
@@ -47,6 +47,18 @@ void breakpoint(void) | |||
47 | x++; | 47 | x++; |
48 | } | 48 | } |
49 | 49 | ||
50 | struct print_arg *alloc_arg(void) | ||
51 | { | ||
52 | struct print_arg *arg; | ||
53 | |||
54 | arg = malloc_or_die(sizeof(*arg)); | ||
55 | if (!arg) | ||
56 | return NULL; | ||
57 | memset(arg, 0, sizeof(*arg)); | ||
58 | |||
59 | return arg; | ||
60 | } | ||
61 | |||
50 | struct cmdline { | 62 | struct cmdline { |
51 | char *comm; | 63 | char *comm; |
52 | int pid; | 64 | int pid; |
@@ -1245,12 +1257,9 @@ process_cond(struct event_format *event, struct print_arg *top, char **tok) | |||
1245 | enum event_type type; | 1257 | enum event_type type; |
1246 | char *token = NULL; | 1258 | char *token = NULL; |
1247 | 1259 | ||
1248 | arg = malloc_or_die(sizeof(*arg)); | 1260 | arg = alloc_arg(); |
1249 | memset(arg, 0, sizeof(*arg)); | 1261 | left = alloc_arg(); |
1250 | 1262 | right = alloc_arg(); | |
1251 | left = malloc_or_die(sizeof(*left)); | ||
1252 | |||
1253 | right = malloc_or_die(sizeof(*right)); | ||
1254 | 1263 | ||
1255 | arg->type = PRINT_OP; | 1264 | arg->type = PRINT_OP; |
1256 | arg->op.left = left; | 1265 | arg->op.left = left; |
@@ -1285,8 +1294,7 @@ process_array(struct event_format *event, struct print_arg *top, char **tok) | |||
1285 | enum event_type type; | 1294 | enum event_type type; |
1286 | char *token = NULL; | 1295 | char *token = NULL; |
1287 | 1296 | ||
1288 | arg = malloc_or_die(sizeof(*arg)); | 1297 | arg = alloc_arg(); |
1289 | memset(arg, 0, sizeof(*arg)); | ||
1290 | 1298 | ||
1291 | *tok = NULL; | 1299 | *tok = NULL; |
1292 | type = process_arg(event, arg, &token); | 1300 | type = process_arg(event, arg, &token); |
@@ -1398,18 +1406,18 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) | |||
1398 | } | 1406 | } |
1399 | 1407 | ||
1400 | /* make an empty left */ | 1408 | /* make an empty left */ |
1401 | left = malloc_or_die(sizeof(*left)); | 1409 | left = alloc_arg(); |
1402 | left->type = PRINT_NULL; | 1410 | left->type = PRINT_NULL; |
1403 | arg->op.left = left; | 1411 | arg->op.left = left; |
1404 | 1412 | ||
1405 | right = malloc_or_die(sizeof(*right)); | 1413 | right = alloc_arg(); |
1406 | arg->op.right = right; | 1414 | arg->op.right = right; |
1407 | 1415 | ||
1408 | type = process_arg(event, right, tok); | 1416 | type = process_arg(event, right, tok); |
1409 | 1417 | ||
1410 | } else if (strcmp(token, "?") == 0) { | 1418 | } else if (strcmp(token, "?") == 0) { |
1411 | 1419 | ||
1412 | left = malloc_or_die(sizeof(*left)); | 1420 | left = alloc_arg(); |
1413 | /* copy the top arg to the left */ | 1421 | /* copy the top arg to the left */ |
1414 | *left = *arg; | 1422 | *left = *arg; |
1415 | 1423 | ||
@@ -1436,7 +1444,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) | |||
1436 | strcmp(token, "==") == 0 || | 1444 | strcmp(token, "==") == 0 || |
1437 | strcmp(token, "!=") == 0) { | 1445 | strcmp(token, "!=") == 0) { |
1438 | 1446 | ||
1439 | left = malloc_or_die(sizeof(*left)); | 1447 | left = alloc_arg(); |
1440 | 1448 | ||
1441 | /* copy the top arg to the left */ | 1449 | /* copy the top arg to the left */ |
1442 | *left = *arg; | 1450 | *left = *arg; |
@@ -1447,7 +1455,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) | |||
1447 | 1455 | ||
1448 | set_op_prio(arg); | 1456 | set_op_prio(arg); |
1449 | 1457 | ||
1450 | right = malloc_or_die(sizeof(*right)); | 1458 | right = alloc_arg(); |
1451 | 1459 | ||
1452 | type = read_token_item(&token); | 1460 | type = read_token_item(&token); |
1453 | *tok = token; | 1461 | *tok = token; |
@@ -1458,7 +1466,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) | |||
1458 | if (left->type != PRINT_ATOM) | 1466 | if (left->type != PRINT_ATOM) |
1459 | die("bad pointer type"); | 1467 | die("bad pointer type"); |
1460 | left->atom.atom = realloc(left->atom.atom, | 1468 | left->atom.atom = realloc(left->atom.atom, |
1461 | sizeof(left->atom.atom) + 3); | 1469 | strlen(left->atom.atom) + 3); |
1462 | strcat(left->atom.atom, " *"); | 1470 | strcat(left->atom.atom, " *"); |
1463 | *arg = *left; | 1471 | *arg = *left; |
1464 | free(left); | 1472 | free(left); |
@@ -1472,7 +1480,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) | |||
1472 | 1480 | ||
1473 | } else if (strcmp(token, "[") == 0) { | 1481 | } else if (strcmp(token, "[") == 0) { |
1474 | 1482 | ||
1475 | left = malloc_or_die(sizeof(*left)); | 1483 | left = alloc_arg(); |
1476 | *left = *arg; | 1484 | *left = *arg; |
1477 | 1485 | ||
1478 | arg->type = PRINT_OP; | 1486 | arg->type = PRINT_OP; |
@@ -1784,7 +1792,7 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char ** | |||
1784 | if (test_type_token(type, token, EVENT_OP, "{")) | 1792 | if (test_type_token(type, token, EVENT_OP, "{")) |
1785 | break; | 1793 | break; |
1786 | 1794 | ||
1787 | arg = malloc_or_die(sizeof(*arg)); | 1795 | arg = alloc_arg(); |
1788 | 1796 | ||
1789 | free_token(token); | 1797 | free_token(token); |
1790 | type = process_arg(event, arg, &token); | 1798 | type = process_arg(event, arg, &token); |
@@ -1837,7 +1845,7 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok) | |||
1837 | if (read_expected_item(EVENT_DELIM, "(") < 0) | 1845 | if (read_expected_item(EVENT_DELIM, "(") < 0) |
1838 | return EVENT_ERROR; | 1846 | return EVENT_ERROR; |
1839 | 1847 | ||
1840 | field = malloc_or_die(sizeof(*field)); | 1848 | field = alloc_arg(); |
1841 | 1849 | ||
1842 | type = process_arg(event, field, &token); | 1850 | type = process_arg(event, field, &token); |
1843 | if (test_type_token(type, token, EVENT_DELIM, ",")) | 1851 | if (test_type_token(type, token, EVENT_DELIM, ",")) |
@@ -1880,7 +1888,7 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok) | |||
1880 | if (read_expected_item(EVENT_DELIM, "(") < 0) | 1888 | if (read_expected_item(EVENT_DELIM, "(") < 0) |
1881 | return EVENT_ERROR; | 1889 | return EVENT_ERROR; |
1882 | 1890 | ||
1883 | field = malloc_or_die(sizeof(*field)); | 1891 | field = alloc_arg(); |
1884 | 1892 | ||
1885 | type = process_arg(event, field, &token); | 1893 | type = process_arg(event, field, &token); |
1886 | if (test_type_token(type, token, EVENT_DELIM, ",")) | 1894 | if (test_type_token(type, token, EVENT_DELIM, ",")) |
@@ -1941,7 +1949,7 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char ** | |||
1941 | return type; | 1949 | return type; |
1942 | 1950 | ||
1943 | free_token(token); | 1951 | free_token(token); |
1944 | arg = malloc_or_die(sizeof(*arg)); | 1952 | arg = alloc_arg(); |
1945 | type = process_arg(event, arg, &token); | 1953 | type = process_arg(event, arg, &token); |
1946 | if (type == EVENT_ERROR) | 1954 | if (type == EVENT_ERROR) |
1947 | goto out_free; | 1955 | goto out_free; |
@@ -1997,8 +2005,7 @@ process_paren(struct event_format *event, struct print_arg *arg, char **tok) | |||
1997 | if (arg->type != PRINT_ATOM) | 2005 | if (arg->type != PRINT_ATOM) |
1998 | die("previous needed to be PRINT_ATOM"); | 2006 | die("previous needed to be PRINT_ATOM"); |
1999 | 2007 | ||
2000 | item_arg = malloc_or_die(sizeof(*item_arg)); | 2008 | item_arg = alloc_arg(); |
2001 | memset(item_arg, 0, sizeof(*item_arg)); | ||
2002 | 2009 | ||
2003 | arg->type = PRINT_TYPE; | 2010 | arg->type = PRINT_TYPE; |
2004 | arg->typecast.type = arg->atom.atom; | 2011 | arg->typecast.type = arg->atom.atom; |
@@ -2132,8 +2139,7 @@ static int event_read_print_args(struct event_format *event, struct print_arg ** | |||
2132 | continue; | 2139 | continue; |
2133 | } | 2140 | } |
2134 | 2141 | ||
2135 | arg = malloc_or_die(sizeof(*arg)); | 2142 | arg = alloc_arg(); |
2136 | memset(arg, 0, sizeof(*arg)); | ||
2137 | 2143 | ||
2138 | type = process_arg(event, arg, &token); | 2144 | type = process_arg(event, arg, &token); |
2139 | 2145 | ||
@@ -2790,7 +2796,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc | |||
2790 | /* | 2796 | /* |
2791 | * The first arg is the IP pointer. | 2797 | * The first arg is the IP pointer. |
2792 | */ | 2798 | */ |
2793 | args = malloc_or_die(sizeof(*args)); | 2799 | args = alloc_arg(); |
2794 | arg = args; | 2800 | arg = args; |
2795 | arg->next = NULL; | 2801 | arg->next = NULL; |
2796 | next = &arg->next; | 2802 | next = &arg->next; |
@@ -2840,7 +2846,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc | |||
2840 | } | 2846 | } |
2841 | val = pevent_read_number(pevent, bptr, ls); | 2847 | val = pevent_read_number(pevent, bptr, ls); |
2842 | bptr += ls; | 2848 | bptr += ls; |
2843 | arg = malloc_or_die(sizeof(*arg)); | 2849 | arg = alloc_arg(); |
2844 | arg->next = NULL; | 2850 | arg->next = NULL; |
2845 | arg->type = PRINT_ATOM; | 2851 | arg->type = PRINT_ATOM; |
2846 | arg->atom.atom = malloc_or_die(32); | 2852 | arg->atom.atom = malloc_or_die(32); |
@@ -2849,7 +2855,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc | |||
2849 | next = &arg->next; | 2855 | next = &arg->next; |
2850 | break; | 2856 | break; |
2851 | case 's': | 2857 | case 's': |
2852 | arg = malloc_or_die(sizeof(*arg)); | 2858 | arg = alloc_arg(); |
2853 | arg->next = NULL; | 2859 | arg->next = NULL; |
2854 | arg->type = PRINT_STRING; | 2860 | arg->type = PRINT_STRING; |
2855 | arg->string.string = strdup(bptr); | 2861 | arg->string.string = strdup(bptr); |
@@ -3646,8 +3652,7 @@ int pevent_parse_event(struct pevent *pevent, | |||
3646 | 3652 | ||
3647 | list = &event->print_fmt.args; | 3653 | list = &event->print_fmt.args; |
3648 | for (field = event->format.fields; field; field = field->next) { | 3654 | for (field = event->format.fields; field; field = field->next) { |
3649 | arg = malloc_or_die(sizeof(*arg)); | 3655 | arg = alloc_arg(); |
3650 | memset(arg, 0, sizeof(*arg)); | ||
3651 | *list = arg; | 3656 | *list = arg; |
3652 | list = &arg->next; | 3657 | list = &arg->next; |
3653 | arg->type = PRINT_FIELD; | 3658 | arg->type = PRINT_FIELD; |
diff --git a/trace-input.c b/trace-input.c index c55e94f..db48c91 100644 --- a/trace-input.c +++ b/trace-input.c | |||
@@ -139,7 +139,7 @@ static char *read_string(struct tracecmd_input *handle) | |||
139 | str[size] = 0; | 139 | str[size] = 0; |
140 | } else { | 140 | } else { |
141 | size = i + 1; | 141 | size = i + 1; |
142 | str = malloc(i); | 142 | str = malloc(size); |
143 | if (!str) | 143 | if (!str) |
144 | return NULL; | 144 | return NULL; |
145 | memcpy(str, buf, i); | 145 | memcpy(str, buf, i); |
@@ -369,13 +369,14 @@ static int read_proc_kallsyms(struct tracecmd_input *handle) | |||
369 | if (size < 0) | 369 | if (size < 0) |
370 | return -1; | 370 | return -1; |
371 | 371 | ||
372 | buf = malloc(size); | 372 | buf = malloc(size+1); |
373 | if (!buf) | 373 | if (!buf) |
374 | return -1; | 374 | return -1; |
375 | if (do_read_check(handle, buf, size)){ | 375 | if (do_read_check(handle, buf, size)){ |
376 | free(buf); | 376 | free(buf); |
377 | return -1; | 377 | return -1; |
378 | } | 378 | } |
379 | buf[size] = 0; | ||
379 | 380 | ||
380 | parse_proc_kallsyms(pevent, buf, size); | 381 | parse_proc_kallsyms(pevent, buf, size); |
381 | 382 | ||
@@ -1334,13 +1335,14 @@ int tracecmd_init_data(struct tracecmd_input *handle) | |||
1334 | size = read8(handle); | 1335 | size = read8(handle); |
1335 | if (size < 0) | 1336 | if (size < 0) |
1336 | return -1; | 1337 | return -1; |
1337 | cmdlines = malloc(size); | 1338 | cmdlines = malloc(size + 1); |
1338 | if (!cmdlines) | 1339 | if (!cmdlines) |
1339 | return -1; | 1340 | return -1; |
1340 | if (do_read_check(handle, cmdlines, size)) { | 1341 | if (do_read_check(handle, cmdlines, size)) { |
1341 | free(cmdlines); | 1342 | free(cmdlines); |
1342 | return -1; | 1343 | return -1; |
1343 | } | 1344 | } |
1345 | cmdlines[size] = 0; | ||
1344 | parse_cmdlines(pevent, cmdlines, size); | 1346 | parse_cmdlines(pevent, cmdlines, size); |
1345 | free(cmdlines); | 1347 | free(cmdlines); |
1346 | 1348 | ||
diff --git a/trace-read.c b/trace-read.c index a7cac1e..b17c271 100644 --- a/trace-read.c +++ b/trace-read.c | |||
@@ -287,7 +287,7 @@ void trace_report (int argc, char **argv) | |||
287 | int show_endian = 0; | 287 | int show_endian = 0; |
288 | int show_page_size = 0; | 288 | int show_page_size = 0; |
289 | int show_printk = 0; | 289 | int show_printk = 0; |
290 | int latency_format; | 290 | int latency_format = 0; |
291 | int show_events = 0; | 291 | int show_events = 0; |
292 | int print_events = 0; | 292 | int print_events = 0; |
293 | int c; | 293 | int c; |