All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Honggyu Kim <hong.gyu.kim@lge.com>,
	namhyung@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] tools lib traceevent: Check the return value of asprintf
Date: Tue, 18 Oct 2016 14:59:17 -0300	[thread overview]
Message-ID: <20161018175917.GW12815@kernel.org> (raw)
In-Reply-To: <20161017141712.11932-2-hong.gyu.kim@lge.com>

Steven, one more, please ack.

- Arnaldo

Em Mon, Oct 17, 2016 at 11:17:11PM +0900, Honggyu Kim escreveu:
> Since asprintf generates a compiler warning when its return value is not
> not properly handled, this patch checks that asprintf call is successful
> or not.
> 
> Signed-off-by: Honggyu Kim <hong.gyu.kim@lge.com>
> ---
>  tools/lib/traceevent/parse-filter.c | 29 +++++++++++++++++++----------
>  1 file changed, 19 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
> index 7c214ce..f0fcdcd 100644
> --- a/tools/lib/traceevent/parse-filter.c
> +++ b/tools/lib/traceevent/parse-filter.c
> @@ -2122,7 +2122,8 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
>  				default:
>  					break;
>  				}
> -				asprintf(&str, val ? "TRUE" : "FALSE");
> +				if (asprintf(&str, val ? "TRUE" : "FALSE") < 0)
> +					return NULL;
>  				break;
>  			}
>  		}
> @@ -2140,7 +2141,8 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
>  			break;
>  		}
>  
> -		asprintf(&str, "(%s) %s (%s)", left, op, right);
> +		if (asprintf(&str, "(%s) %s (%s)", left, op, right) < 0)
> +			return NULL;
>  		break;
>  
>  	case FILTER_OP_NOT:
> @@ -2156,10 +2158,12 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
>  			right_val = 0;
>  		if (right_val >= 0) {
>  			/* just return the opposite */
> -			asprintf(&str, right_val ? "FALSE" : "TRUE");
> +			if (asprintf(&str, right_val ? "FALSE" : "TRUE") < 0)
> +				return NULL;
>  			break;
>  		}
> -		asprintf(&str, "%s(%s)", op, right);
> +		if (asprintf(&str, "%s(%s)", op, right) < 0)
> +			return NULL;
>  		break;
>  
>  	default:
> @@ -2175,7 +2179,8 @@ static char *val_to_str(struct event_filter *filter, struct filter_arg *arg)
>  {
>  	char *str = NULL;
>  
> -	asprintf(&str, "%lld", arg->value.val);
> +	if (asprintf(&str, "%lld", arg->value.val) < 0)
> +		return NULL;
>  
>  	return str;
>  }
> @@ -2233,7 +2238,8 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg)
>  		break;
>  	}
>  
> -	asprintf(&str, "%s %s %s", lstr, op, rstr);
> +	if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0)
> +		return NULL;
>  out:
>  	free(lstr);
>  	free(rstr);
> @@ -2277,7 +2283,8 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg)
>  		if (!op)
>  			op = "<=";
>  
> -		asprintf(&str, "%s %s %s", lstr, op, rstr);
> +		if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0)
> +			return NULL;
>  		break;
>  
>  	default:
> @@ -2312,8 +2319,9 @@ static char *str_to_str(struct event_filter *filter, struct filter_arg *arg)
>  		if (!op)
>  			op = "!~";
>  
> -		asprintf(&str, "%s %s \"%s\"",
> -			 arg->str.field->name, op, arg->str.val);
> +		if (asprintf(&str, "%s %s \"%s\"",
> +			 arg->str.field->name, op, arg->str.val) < 0)
> +			return NULL;
>  		break;
>  
>  	default:
> @@ -2329,7 +2337,8 @@ static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg)
>  
>  	switch (arg->type) {
>  	case FILTER_ARG_BOOLEAN:
> -		asprintf(&str, arg->boolean.value ? "TRUE" : "FALSE");
> +		if (asprintf(&str, arg->boolean.value ? "TRUE" : "FALSE") < 0)
> +			return NULL;
>  		return str;
>  
>  	case FILTER_ARG_OP:
> -- 
> 2.10.0.rc2.dirty

  reply	other threads:[~2016-10-18 17:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-17 14:17 [PATCH 1/3] tools lib traceevent: Add -O2 option to traceevent Honggyu Kim
2016-10-17 14:17 ` [PATCH 2/3] tools lib traceevent: Check the return value of asprintf Honggyu Kim
2016-10-18 17:59   ` Arnaldo Carvalho de Melo [this message]
2016-10-19  0:25     ` Namhyung Kim
2016-10-17 14:17 ` [PATCH 3/3] tools lib traceevent: Fix to set uninitialized variables Honggyu Kim
2016-10-18 17:59   ` Arnaldo Carvalho de Melo
2016-10-18  2:01 ` [PATCH 1/3] tools lib traceevent: Add -O2 option to traceevent Namhyung Kim
2016-10-18 15:29   ` Steven Rostedt
2016-10-19 17:48     ` Arnaldo Carvalho de Melo
2016-10-19 18:05       ` Arnaldo Carvalho de Melo
2016-10-19 18:06         ` Arnaldo Carvalho de Melo
2016-10-19 19:26           ` Steven Rostedt
2016-10-19 19:21         ` Steven Rostedt
2016-10-19 18:21       ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161018175917.GW12815@kernel.org \
    --to=acme@kernel.org \
    --cc=hong.gyu.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.