Commit f23b24f1 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

tools lib traceevent: Get rid of die() in some string conversion functions

Those functions stringify filter arguments.

As caller of those functions handles NULL string properly, it seems that
it's enough to return NULL rather than calling die().
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/878uvkgx9f.fsf@sejong.aot.lge.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 5f70619d
...@@ -1361,8 +1361,10 @@ enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter, ...@@ -1361,8 +1361,10 @@ enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter,
if (ret >= 0 && pevent->test_filters) { if (ret >= 0 && pevent->test_filters) {
char *test; char *test;
test = pevent_filter_make_string(filter, event->event->id); test = pevent_filter_make_string(filter, event->event->id);
printf(" '%s: %s'\n", event->event->name, test); if (test) {
free(test); printf(" '%s: %s'\n", event->event->name, test);
free(test);
}
} }
} }
...@@ -2050,7 +2052,6 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) ...@@ -2050,7 +2052,6 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
int left_val = -1; int left_val = -1;
int right_val = -1; int right_val = -1;
int val; int val;
int len;
switch (arg->op.type) { switch (arg->op.type) {
case FILTER_OP_AND: case FILTER_OP_AND:
...@@ -2097,11 +2098,7 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) ...@@ -2097,11 +2098,7 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
default: default:
break; break;
} }
str = malloc_or_die(6); asprintf(&str, val ? "TRUE" : "FALSE");
if (val)
strcpy(str, "TRUE");
else
strcpy(str, "FALSE");
break; break;
} }
} }
...@@ -2119,10 +2116,7 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) ...@@ -2119,10 +2116,7 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
break; break;
} }
len = strlen(left) + strlen(right) + strlen(op) + 10; asprintf(&str, "(%s) %s (%s)", left, op, right);
str = malloc_or_die(len);
snprintf(str, len, "(%s) %s (%s)",
left, op, right);
break; break;
case FILTER_OP_NOT: case FILTER_OP_NOT:
...@@ -2138,16 +2132,10 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) ...@@ -2138,16 +2132,10 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
right_val = 0; right_val = 0;
if (right_val >= 0) { if (right_val >= 0) {
/* just return the opposite */ /* just return the opposite */
str = malloc_or_die(6); asprintf(&str, right_val ? "FALSE" : "TRUE");
if (right_val)
strcpy(str, "FALSE");
else
strcpy(str, "TRUE");
break; break;
} }
len = strlen(right) + strlen(op) + 3; asprintf(&str, "%s(%s)", op, right);
str = malloc_or_die(len);
snprintf(str, len, "%s(%s)", op, right);
break; break;
default: default:
...@@ -2161,11 +2149,9 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) ...@@ -2161,11 +2149,9 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
static char *val_to_str(struct event_filter *filter, struct filter_arg *arg) static char *val_to_str(struct event_filter *filter, struct filter_arg *arg)
{ {
char *str; char *str = NULL;
str = malloc_or_die(30);
snprintf(str, 30, "%lld", arg->value.val); asprintf(&str, "%lld", arg->value.val);
return str; return str;
} }
...@@ -2181,7 +2167,6 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg) ...@@ -2181,7 +2167,6 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg)
char *rstr; char *rstr;
char *op; char *op;
char *str = NULL; char *str = NULL;
int len;
lstr = arg_to_str(filter, arg->exp.left); lstr = arg_to_str(filter, arg->exp.left);
rstr = arg_to_str(filter, arg->exp.right); rstr = arg_to_str(filter, arg->exp.right);
...@@ -2220,12 +2205,11 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg) ...@@ -2220,12 +2205,11 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg)
op = "^"; op = "^";
break; break;
default: default:
die("oops in exp"); op = "[ERROR IN EXPRESSION TYPE]";
break;
} }
len = strlen(op) + strlen(lstr) + strlen(rstr) + 4; asprintf(&str, "%s %s %s", lstr, op, rstr);
str = malloc_or_die(len);
snprintf(str, len, "%s %s %s", lstr, op, rstr);
out: out:
free(lstr); free(lstr);
free(rstr); free(rstr);
...@@ -2239,7 +2223,6 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg) ...@@ -2239,7 +2223,6 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg)
char *rstr; char *rstr;
char *str = NULL; char *str = NULL;
char *op = NULL; char *op = NULL;
int len;
lstr = arg_to_str(filter, arg->num.left); lstr = arg_to_str(filter, arg->num.left);
rstr = arg_to_str(filter, arg->num.right); rstr = arg_to_str(filter, arg->num.right);
...@@ -2270,10 +2253,7 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg) ...@@ -2270,10 +2253,7 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg)
if (!op) if (!op)
op = "<="; op = "<=";
len = strlen(lstr) + strlen(op) + strlen(rstr) + 4; asprintf(&str, "%s %s %s", lstr, op, rstr);
str = malloc_or_die(len);
sprintf(str, "%s %s %s", lstr, op, rstr);
break; break;
default: default:
...@@ -2291,7 +2271,6 @@ static char *str_to_str(struct event_filter *filter, struct filter_arg *arg) ...@@ -2291,7 +2271,6 @@ static char *str_to_str(struct event_filter *filter, struct filter_arg *arg)
{ {
char *str = NULL; char *str = NULL;
char *op = NULL; char *op = NULL;
int len;
switch (arg->str.type) { switch (arg->str.type) {
case FILTER_CMP_MATCH: case FILTER_CMP_MATCH:
...@@ -2309,12 +2288,8 @@ static char *str_to_str(struct event_filter *filter, struct filter_arg *arg) ...@@ -2309,12 +2288,8 @@ static char *str_to_str(struct event_filter *filter, struct filter_arg *arg)
if (!op) if (!op)
op = "!~"; op = "!~";
len = strlen(arg->str.field->name) + strlen(op) + asprintf(&str, "%s %s \"%s\"",
strlen(arg->str.val) + 6; arg->str.field->name, op, arg->str.val);
str = malloc_or_die(len);
snprintf(str, len, "%s %s \"%s\"",
arg->str.field->name,
op, arg->str.val);
break; break;
default: default:
...@@ -2326,15 +2301,11 @@ static char *str_to_str(struct event_filter *filter, struct filter_arg *arg) ...@@ -2326,15 +2301,11 @@ static char *str_to_str(struct event_filter *filter, struct filter_arg *arg)
static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg) static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg)
{ {
char *str; char *str = NULL;
switch (arg->type) { switch (arg->type) {
case FILTER_ARG_BOOLEAN: case FILTER_ARG_BOOLEAN:
str = malloc_or_die(6); asprintf(&str, arg->boolean.value ? "TRUE" : "FALSE");
if (arg->boolean.value)
strcpy(str, "TRUE");
else
strcpy(str, "FALSE");
return str; return str;
case FILTER_ARG_OP: case FILTER_ARG_OP:
...@@ -2369,7 +2340,7 @@ static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg) ...@@ -2369,7 +2340,7 @@ static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg)
* *
* Returns a string that displays the filter contents. * Returns a string that displays the filter contents.
* This string must be freed with free(str). * This string must be freed with free(str).
* NULL is returned if no filter is found. * NULL is returned if no filter is found or allocation failed.
*/ */
char * char *
pevent_filter_make_string(struct event_filter *filter, int event_id) pevent_filter_make_string(struct event_filter *filter, int event_id)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment