linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trace-cmd: always initialize write_record() len
@ 2019-06-27 15:25 Greg Thelen
  2019-06-27 15:40 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Greg Thelen @ 2019-06-27 15:25 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: linux-trace-devel, Greg Thelen

write_record() uses an uninitializedd 'len' when record->size is 0.  I'm
not sure how likely this case is.

To be safe and silence compiler warning, unconditionally initialize len.

Signed-off-by: Greg Thelen <gthelen@google.com>
---
 tracecmd/trace-split.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c
index d27b3c65badc..6c8a774e13d0 100644
--- a/tracecmd/trace-split.c
+++ b/tracecmd/trace-split.c
@@ -80,7 +80,7 @@ static int write_record(struct tracecmd_input *handle,
 	unsigned long long diff;
 	struct tep_handle *pevent;
 	void *page;
-	int len;
+	int len = 0;
 	char *ptr;
 	int index = 0;
 	int time;
@@ -106,12 +106,8 @@ static int write_record(struct tracecmd_input *handle,
 		return 0;
 	}
 
-	if (record->size) {
-		if (record->size < 28 * 4)
-			len = record->size / 4;
-		else
-			len = 0;
-	}
+	if (record->size && (record->size < 28 * 4))
+		len = record->size / 4;
 
 	time = (unsigned)diff;
 	time = create_type_len(pevent, time, len);
-- 
2.22.0.410.gd8fdbe21b5-goog


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

* Re: [PATCH] trace-cmd: always initialize write_record() len
  2019-06-27 15:25 [PATCH] trace-cmd: always initialize write_record() len Greg Thelen
@ 2019-06-27 15:40 ` Steven Rostedt
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2019-06-27 15:40 UTC (permalink / raw)
  To: Greg Thelen; +Cc: linux-trace-devel

On Thu, 27 Jun 2019 08:25:02 -0700
Greg Thelen <gthelen@google.com> wrote:

Hi Greg,

> write_record() uses an uninitializedd 'len' when record->size is 0.  I'm
> not sure how likely this case is.

Hmm, yeah, I guess it can be zero, as it's the data size, not the
record true size. If we had a zero size data record, I guess it would
still exist.

> 
> To be safe and silence compiler warning, unconditionally initialize len.

Looks good to me. I'll add it to the queue.

Thanks!

-- Steve

> 
> Signed-off-by: Greg Thelen <gthelen@google.com>
> ---
>  tracecmd/trace-split.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c
> index d27b3c65badc..6c8a774e13d0 100644
> --- a/tracecmd/trace-split.c
> +++ b/tracecmd/trace-split.c
> @@ -80,7 +80,7 @@ static int write_record(struct tracecmd_input *handle,
>  	unsigned long long diff;
>  	struct tep_handle *pevent;
>  	void *page;
> -	int len;
> +	int len = 0;
>  	char *ptr;
>  	int index = 0;
>  	int time;
> @@ -106,12 +106,8 @@ static int write_record(struct tracecmd_input *handle,
>  		return 0;
>  	}
>  
> -	if (record->size) {
> -		if (record->size < 28 * 4)
> -			len = record->size / 4;
> -		else
> -			len = 0;
> -	}
> +	if (record->size && (record->size < 28 * 4))
> +		len = record->size / 4;
>  
>  	time = (unsigned)diff;
>  	time = create_type_len(pevent, time, len);


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

end of thread, other threads:[~2019-06-27 15:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-27 15:25 [PATCH] trace-cmd: always initialize write_record() len Greg Thelen
2019-06-27 15:40 ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).