Commit f8ff18be authored by He Zhe's avatar He Zhe Committed by Arnaldo Carvalho de Melo

tools lib traceevent: Take care of return value of asprintf

According to the API, if memory allocation wasn't possible, or some
other error occurs, asprintf will return -1, and the contents of strp
below are undefined.

  int asprintf(char **strp, const char *fmt, ...);

This patch takes care of return value of asprintf to make it less error
prone and prevent the following build warning.

  ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
Signed-off-by: default avatarHe Zhe <zhe.he@windriver.com>
Reviewed-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: hewenliang4@huawei.com
Link: http://lore.kernel.org/lkml/1582163930-233692-1-git-send-email-zhe.he@windriver.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent bec49a9e
...@@ -1958,7 +1958,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a ...@@ -1958,7 +1958,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
default: default:
break; break;
} }
asprintf(&str, val ? "TRUE" : "FALSE"); if (asprintf(&str, val ? "TRUE" : "FALSE") < 0)
str = NULL;
break; break;
} }
} }
...@@ -1976,7 +1977,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a ...@@ -1976,7 +1977,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
break; break;
} }
asprintf(&str, "(%s) %s (%s)", left, op, right); if (asprintf(&str, "(%s) %s (%s)", left, op, right) < 0)
str = NULL;
break; break;
case TEP_FILTER_OP_NOT: case TEP_FILTER_OP_NOT:
...@@ -1992,10 +1994,12 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a ...@@ -1992,10 +1994,12 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
right_val = 0; right_val = 0;
if (right_val >= 0) { if (right_val >= 0) {
/* just return the opposite */ /* just return the opposite */
asprintf(&str, right_val ? "FALSE" : "TRUE"); if (asprintf(&str, right_val ? "FALSE" : "TRUE") < 0)
str = NULL;
break; break;
} }
asprintf(&str, "%s(%s)", op, right); if (asprintf(&str, "%s(%s)", op, right) < 0)
str = NULL;
break; break;
default: default:
...@@ -2011,7 +2015,8 @@ static char *val_to_str(struct tep_event_filter *filter, struct tep_filter_arg * ...@@ -2011,7 +2015,8 @@ static char *val_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
{ {
char *str = NULL; char *str = NULL;
asprintf(&str, "%lld", arg->value.val); if (asprintf(&str, "%lld", arg->value.val) < 0)
str = NULL;
return str; return str;
} }
...@@ -2069,7 +2074,8 @@ static char *exp_to_str(struct tep_event_filter *filter, struct tep_filter_arg * ...@@ -2069,7 +2074,8 @@ static char *exp_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
break; break;
} }
asprintf(&str, "%s %s %s", lstr, op, rstr); if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0)
str = NULL;
out: out:
free(lstr); free(lstr);
free(rstr); free(rstr);
...@@ -2113,7 +2119,8 @@ static char *num_to_str(struct tep_event_filter *filter, struct tep_filter_arg * ...@@ -2113,7 +2119,8 @@ static char *num_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
if (!op) if (!op)
op = "<="; op = "<=";
asprintf(&str, "%s %s %s", lstr, op, rstr); if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0)
str = NULL;
break; break;
default: default:
...@@ -2148,8 +2155,9 @@ static char *str_to_str(struct tep_event_filter *filter, struct tep_filter_arg * ...@@ -2148,8 +2155,9 @@ static char *str_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
if (!op) if (!op)
op = "!~"; op = "!~";
asprintf(&str, "%s %s \"%s\"", if (asprintf(&str, "%s %s \"%s\"",
arg->str.field->name, op, arg->str.val); arg->str.field->name, op, arg->str.val) < 0)
str = NULL;
break; break;
default: default:
...@@ -2165,7 +2173,8 @@ static char *arg_to_str(struct tep_event_filter *filter, struct tep_filter_arg * ...@@ -2165,7 +2173,8 @@ static char *arg_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
switch (arg->type) { switch (arg->type) {
case TEP_FILTER_ARG_BOOLEAN: case TEP_FILTER_ARG_BOOLEAN:
asprintf(&str, arg->boolean.value ? "TRUE" : "FALSE"); if (asprintf(&str, arg->boolean.value ? "TRUE" : "FALSE") < 0)
str = NULL;
return str; return str;
case TEP_FILTER_ARG_OP: case TEP_FILTER_ARG_OP:
......
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