Messages in this thread |  | | From | Namhyung Kim <> | Subject | Re: [PATCH 13/14] tools lib traceevent: Get rid of die() in some string conversion funcitons | Date | Mon, 16 Dec 2013 13:49:11 +0900 |
| |
Hi Arnaldo,
On Fri, 13 Dec 2013 11:52:04 -0300, Arnaldo Carvalho de Melo wrote: >> - str = malloc_or_die(6); >> + str = malloc(6); >> + if (str == NULL) >> + break; >> if (val) >> strcpy(str, "TRUE"); >> else > > The malloc here can be combined with the strcpy, and the else clause > gets immediately after: > > if (asprintf(&str, "%s", "TRUE") < 0) > >> @@ -2119,10 +2122,7 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) >> break; >> } >> >> - len = strlen(left) + strlen(right) + strlen(op) + 10; >> - str = malloc_or_die(len); >> - snprintf(str, len, "(%s) %s (%s)", >> - left, op, right); >> + asprintf(&str, "(%s) %s (%s)", left, op, right); >> break; > > I was unsure if str was NULL, it is already, at decl site, good :) > > All the rest is ok, so its just the malloc + strcpy that remains to be > converted, do you want me to do it?
Hmm.. did you mean like this?
str = NULL; if (val) asprintf(&str, "TRUE"); else asprintf(&str, "FALSE"); return str;
Thanks, Namhyung
|  |