All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] tools lib traceevent: Take care of return value of asprintf
@ 2020-02-20  1:58 zhe.he
  2020-03-25 13:05 ` He Zhe
  2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for He Zhe
  0 siblings, 2 replies; 8+ messages in thread
From: zhe.he @ 2020-02-20  1:58 UTC (permalink / raw)
  To: rostedt, acme, tstoyanov, hewenliang4, linux-kernel, zhe.he

From: He Zhe <zhe.he@windriver.com>

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: He Zhe <zhe.he@windriver.com>
---
v2: directly check the return value without saving to a variable
v3: as asked, not remove those that already save the return value

 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 20eed71..c271aee 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -1958,7 +1958,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
 				default:
 					break;
 				}
-				asprintf(&str, val ? "TRUE" : "FALSE");
+				if (asprintf(&str, val ? "TRUE" : "FALSE") < 0)
+					str = NULL;
 				break;
 			}
 		}
@@ -1976,7 +1977,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
 			break;
 		}
 
-		asprintf(&str, "(%s) %s (%s)", left, op, right);
+		if (asprintf(&str, "(%s) %s (%s)", left, op, right) < 0)
+			str = NULL;
 		break;
 
 	case TEP_FILTER_OP_NOT:
@@ -1992,10 +1994,12 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
 			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)
+				str = NULL;
 			break;
 		}
-		asprintf(&str, "%s(%s)", op, right);
+		if (asprintf(&str, "%s(%s)", op, right) < 0)
+			str = NULL;
 		break;
 
 	default:
@@ -2011,7 +2015,8 @@ static char *val_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
 {
 	char *str = NULL;
 
-	asprintf(&str, "%lld", arg->value.val);
+	if (asprintf(&str, "%lld", arg->value.val) < 0)
+		str = NULL;
 
 	return str;
 }
@@ -2069,7 +2074,8 @@ static char *exp_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
 		break;
 	}
 
-	asprintf(&str, "%s %s %s", lstr, op, rstr);
+	if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0)
+		str = NULL;
 out:
 	free(lstr);
 	free(rstr);
@@ -2113,7 +2119,8 @@ static char *num_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
 		if (!op)
 			op = "<=";
 
-		asprintf(&str, "%s %s %s", lstr, op, rstr);
+		if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0)
+			str = NULL;
 		break;
 
 	default:
@@ -2148,8 +2155,9 @@ static char *str_to_str(struct tep_event_filter *filter, struct tep_filter_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)
+			str = NULL;
 		break;
 
 	default:
@@ -2165,7 +2173,8 @@ static char *arg_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
 
 	switch (arg->type) {
 	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;
 
 	case TEP_FILTER_ARG_OP:
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] tools lib traceevent: Take care of return value of asprintf
  2020-02-20  1:58 [PATCH v3] tools lib traceevent: Take care of return value of asprintf zhe.he
@ 2020-03-25 13:05 ` He Zhe
  2020-03-25 13:24   ` Steven Rostedt
  2020-03-25 13:35   ` Arnaldo Carvalho de Melo
  2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for He Zhe
  1 sibling, 2 replies; 8+ messages in thread
From: He Zhe @ 2020-03-25 13:05 UTC (permalink / raw)
  To: rostedt, acme, tstoyanov, hewenliang4, linux-kernel

Can this be considered for the moment?

Thanks,
Zhe

On 2/20/20 9:58 AM, zhe.he@windriver.com wrote:
> From: He Zhe <zhe.he@windriver.com>
>
> 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: He Zhe <zhe.he@windriver.com>
> ---
> v2: directly check the return value without saving to a variable
> v3: as asked, not remove those that already save the return value
>
>  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 20eed71..c271aee 100644
> --- a/tools/lib/traceevent/parse-filter.c
> +++ b/tools/lib/traceevent/parse-filter.c
> @@ -1958,7 +1958,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
>  				default:
>  					break;
>  				}
> -				asprintf(&str, val ? "TRUE" : "FALSE");
> +				if (asprintf(&str, val ? "TRUE" : "FALSE") < 0)
> +					str = NULL;
>  				break;
>  			}
>  		}
> @@ -1976,7 +1977,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
>  			break;
>  		}
>  
> -		asprintf(&str, "(%s) %s (%s)", left, op, right);
> +		if (asprintf(&str, "(%s) %s (%s)", left, op, right) < 0)
> +			str = NULL;
>  		break;
>  
>  	case TEP_FILTER_OP_NOT:
> @@ -1992,10 +1994,12 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
>  			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)
> +				str = NULL;
>  			break;
>  		}
> -		asprintf(&str, "%s(%s)", op, right);
> +		if (asprintf(&str, "%s(%s)", op, right) < 0)
> +			str = NULL;
>  		break;
>  
>  	default:
> @@ -2011,7 +2015,8 @@ static char *val_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
>  {
>  	char *str = NULL;
>  
> -	asprintf(&str, "%lld", arg->value.val);
> +	if (asprintf(&str, "%lld", arg->value.val) < 0)
> +		str = NULL;
>  
>  	return str;
>  }
> @@ -2069,7 +2074,8 @@ static char *exp_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
>  		break;
>  	}
>  
> -	asprintf(&str, "%s %s %s", lstr, op, rstr);
> +	if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0)
> +		str = NULL;
>  out:
>  	free(lstr);
>  	free(rstr);
> @@ -2113,7 +2119,8 @@ static char *num_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
>  		if (!op)
>  			op = "<=";
>  
> -		asprintf(&str, "%s %s %s", lstr, op, rstr);
> +		if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0)
> +			str = NULL;
>  		break;
>  
>  	default:
> @@ -2148,8 +2155,9 @@ static char *str_to_str(struct tep_event_filter *filter, struct tep_filter_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)
> +			str = NULL;
>  		break;
>  
>  	default:
> @@ -2165,7 +2173,8 @@ static char *arg_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
>  
>  	switch (arg->type) {
>  	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;
>  
>  	case TEP_FILTER_ARG_OP:


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] tools lib traceevent: Take care of return value of asprintf
  2020-03-25 13:05 ` He Zhe
@ 2020-03-25 13:24   ` Steven Rostedt
  2020-03-25 13:35   ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 8+ messages in thread
From: Steven Rostedt @ 2020-03-25 13:24 UTC (permalink / raw)
  To: He Zhe; +Cc: acme, tstoyanov, hewenliang4, linux-kernel

On Wed, 25 Mar 2020 21:05:46 +0800
He Zhe <zhe.he@windriver.com> wrote:

> Can this be considered for the moment?
> 

Thanks for the reminder. This patch was pushed down in my queue by lots of
other patches I need to review. I'll try to take a look at it this week.

-- Steve

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] tools lib traceevent: Take care of return value of asprintf
  2020-03-25 13:05 ` He Zhe
  2020-03-25 13:24   ` Steven Rostedt
@ 2020-03-25 13:35   ` Arnaldo Carvalho de Melo
  2020-04-07  2:24     ` Steven Rostedt
  1 sibling, 1 reply; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-03-25 13:35 UTC (permalink / raw)
  To: Steven Rostedt, He Zhe; +Cc: tstoyanov, hewenliang4, linux-kernel, acme

Em Wed, Mar 25, 2020 at 09:05:46PM +0800, He Zhe escreveu:
> Can this be considered for the moment?

Rostedt, have you looked at this?

- Arnaldo
 
> Thanks,
> Zhe
> 
> On 2/20/20 9:58 AM, zhe.he@windriver.com wrote:
> > From: He Zhe <zhe.he@windriver.com>
> >
> > 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: He Zhe <zhe.he@windriver.com>
> > ---
> > v2: directly check the return value without saving to a variable
> > v3: as asked, not remove those that already save the return value
> >
> >  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 20eed71..c271aee 100644
> > --- a/tools/lib/traceevent/parse-filter.c
> > +++ b/tools/lib/traceevent/parse-filter.c
> > @@ -1958,7 +1958,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
> >  				default:
> >  					break;
> >  				}
> > -				asprintf(&str, val ? "TRUE" : "FALSE");
> > +				if (asprintf(&str, val ? "TRUE" : "FALSE") < 0)
> > +					str = NULL;
> >  				break;
> >  			}
> >  		}
> > @@ -1976,7 +1977,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
> >  			break;
> >  		}
> >  
> > -		asprintf(&str, "(%s) %s (%s)", left, op, right);
> > +		if (asprintf(&str, "(%s) %s (%s)", left, op, right) < 0)
> > +			str = NULL;
> >  		break;
> >  
> >  	case TEP_FILTER_OP_NOT:
> > @@ -1992,10 +1994,12 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
> >  			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)
> > +				str = NULL;
> >  			break;
> >  		}
> > -		asprintf(&str, "%s(%s)", op, right);
> > +		if (asprintf(&str, "%s(%s)", op, right) < 0)
> > +			str = NULL;
> >  		break;
> >  
> >  	default:
> > @@ -2011,7 +2015,8 @@ static char *val_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
> >  {
> >  	char *str = NULL;
> >  
> > -	asprintf(&str, "%lld", arg->value.val);
> > +	if (asprintf(&str, "%lld", arg->value.val) < 0)
> > +		str = NULL;
> >  
> >  	return str;
> >  }
> > @@ -2069,7 +2074,8 @@ static char *exp_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
> >  		break;
> >  	}
> >  
> > -	asprintf(&str, "%s %s %s", lstr, op, rstr);
> > +	if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0)
> > +		str = NULL;
> >  out:
> >  	free(lstr);
> >  	free(rstr);
> > @@ -2113,7 +2119,8 @@ static char *num_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
> >  		if (!op)
> >  			op = "<=";
> >  
> > -		asprintf(&str, "%s %s %s", lstr, op, rstr);
> > +		if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0)
> > +			str = NULL;
> >  		break;
> >  
> >  	default:
> > @@ -2148,8 +2155,9 @@ static char *str_to_str(struct tep_event_filter *filter, struct tep_filter_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)
> > +			str = NULL;
> >  		break;
> >  
> >  	default:
> > @@ -2165,7 +2173,8 @@ static char *arg_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
> >  
> >  	switch (arg->type) {
> >  	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;
> >  
> >  	case TEP_FILTER_ARG_OP:


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] tools lib traceevent: Take care of return value of asprintf
  2020-03-25 13:35   ` Arnaldo Carvalho de Melo
@ 2020-04-07  2:24     ` Steven Rostedt
  2020-04-07 12:33       ` Arnaldo Carvalho de Melo
  2020-04-16 16:08       ` Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 8+ messages in thread
From: Steven Rostedt @ 2020-04-07  2:24 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: He Zhe, tstoyanov, hewenliang4, linux-kernel, acme

On Wed, 25 Mar 2020 10:35:51 -0300
Arnaldo Carvalho de Melo <acme@redhat.com> wrote:

> Em Wed, Mar 25, 2020 at 09:05:46PM +0800, He Zhe escreveu:
> > Can this be considered for the moment?  
> 
> Rostedt, have you looked at this?
> 

Bah, I did but forgot to reply.

Yes, add my Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

Sorry for not sending this out earlier.

-- Steve

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] tools lib traceevent: Take care of return value of asprintf
  2020-04-07  2:24     ` Steven Rostedt
@ 2020-04-07 12:33       ` Arnaldo Carvalho de Melo
  2020-04-16 16:08       ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-04-07 12:33 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Arnaldo Carvalho de Melo, He Zhe, tstoyanov, hewenliang4, linux-kernel

Em Mon, Apr 06, 2020 at 10:24:11PM -0400, Steven Rostedt escreveu:
> On Wed, 25 Mar 2020 10:35:51 -0300
> Arnaldo Carvalho de Melo <acme@redhat.com> wrote:
> 
> > Em Wed, Mar 25, 2020 at 09:05:46PM +0800, He Zhe escreveu:
> > > Can this be considered for the moment?  
> > 
> > Rostedt, have you looked at this?
> > 
> 
> Bah, I did but forgot to reply.
> 
> Yes, add my Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> 
> Sorry for not sending this out earlier.

no problem, I'm finishing a round of tests to submit a batch to Ingo,
will pick it up for the next one.

Thanks,

- Arnaldo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] tools lib traceevent: Take care of return value of asprintf
  2020-04-07  2:24     ` Steven Rostedt
  2020-04-07 12:33       ` Arnaldo Carvalho de Melo
@ 2020-04-16 16:08       ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-04-16 16:08 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Arnaldo Carvalho de Melo, He Zhe, tstoyanov, hewenliang4, linux-kernel

Em Mon, Apr 06, 2020 at 10:24:11PM -0400, Steven Rostedt escreveu:
> On Wed, 25 Mar 2020 10:35:51 -0300
> Arnaldo Carvalho de Melo <acme@redhat.com> wrote:
> 
> > Em Wed, Mar 25, 2020 at 09:05:46PM +0800, He Zhe escreveu:
> > > Can this be considered for the moment?  
> > 
> > Rostedt, have you looked at this?
> > 
> 
> Bah, I did but forgot to reply.
> 
> Yes, add my Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> 
> Sorry for not sending this out earlier.

Thanks, finally applied.

- Arnaldo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tip: perf/core] tools lib traceevent: Take care of return value of asprintf
  2020-02-20  1:58 [PATCH v3] tools lib traceevent: Take care of return value of asprintf zhe.he
  2020-03-25 13:05 ` He Zhe
@ 2020-04-22 12:17 ` tip-bot2 for He Zhe
  1 sibling, 0 replies; 8+ messages in thread
From: tip-bot2 for He Zhe @ 2020-04-22 12:17 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: He Zhe, Steven Rostedt (VMware),
	Tzvetomir Stoyanov, hewenliang4, Arnaldo Carvalho de Melo, x86,
	LKML

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     f8ff18be1f5c6ba1c2befb043bea6e7eaf9f8987
Gitweb:        https://git.kernel.org/tip/f8ff18be1f5c6ba1c2befb043bea6e7eaf9f8987
Author:        He Zhe <zhe.he@windriver.com>
AuthorDate:    Thu, 20 Feb 2020 09:58:50 +08:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Sat, 18 Apr 2020 09:05:00 -03:00

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: He Zhe <zhe.he@windriver.com>
Reviewed-by: Steven 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.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.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 20eed71..c271aee 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -1958,7 +1958,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
 				default:
 					break;
 				}
-				asprintf(&str, val ? "TRUE" : "FALSE");
+				if (asprintf(&str, val ? "TRUE" : "FALSE") < 0)
+					str = NULL;
 				break;
 			}
 		}
@@ -1976,7 +1977,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
 			break;
 		}
 
-		asprintf(&str, "(%s) %s (%s)", left, op, right);
+		if (asprintf(&str, "(%s) %s (%s)", left, op, right) < 0)
+			str = NULL;
 		break;
 
 	case TEP_FILTER_OP_NOT:
@@ -1992,10 +1994,12 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a
 			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)
+				str = NULL;
 			break;
 		}
-		asprintf(&str, "%s(%s)", op, right);
+		if (asprintf(&str, "%s(%s)", op, right) < 0)
+			str = NULL;
 		break;
 
 	default:
@@ -2011,7 +2015,8 @@ static char *val_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
 {
 	char *str = NULL;
 
-	asprintf(&str, "%lld", arg->value.val);
+	if (asprintf(&str, "%lld", arg->value.val) < 0)
+		str = NULL;
 
 	return str;
 }
@@ -2069,7 +2074,8 @@ static char *exp_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
 		break;
 	}
 
-	asprintf(&str, "%s %s %s", lstr, op, rstr);
+	if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0)
+		str = NULL;
 out:
 	free(lstr);
 	free(rstr);
@@ -2113,7 +2119,8 @@ static char *num_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
 		if (!op)
 			op = "<=";
 
-		asprintf(&str, "%s %s %s", lstr, op, rstr);
+		if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0)
+			str = NULL;
 		break;
 
 	default:
@@ -2148,8 +2155,9 @@ static char *str_to_str(struct tep_event_filter *filter, struct tep_filter_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)
+			str = NULL;
 		break;
 
 	default:
@@ -2165,7 +2173,8 @@ static char *arg_to_str(struct tep_event_filter *filter, struct tep_filter_arg *
 
 	switch (arg->type) {
 	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;
 
 	case TEP_FILTER_ARG_OP:

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-04-22 12:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-20  1:58 [PATCH v3] tools lib traceevent: Take care of return value of asprintf zhe.he
2020-03-25 13:05 ` He Zhe
2020-03-25 13:24   ` Steven Rostedt
2020-03-25 13:35   ` Arnaldo Carvalho de Melo
2020-04-07  2:24     ` Steven Rostedt
2020-04-07 12:33       ` Arnaldo Carvalho de Melo
2020-04-16 16:08       ` Arnaldo Carvalho de Melo
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for He Zhe

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.