Skip to contentSkip to conversation

trace-cmd: always initialize write_record() len

PATCH In review Greg Thelen 2 participants 2 messages Jun 27, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd: always initialize write_record() len

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.

---
 tracecmd/trace-split.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
tracecmd/trace-split.c +3 -7
index d27b3c65badc..6c8a774e13d0 100644
@@ -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);
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#1 lore raw

On Thu, 27 Jun 2019 08:25:02 -0700
Greg Thelen <[email protected]> wrote:

Hi Greg,

Quoted 2 lines

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.

Quoted 2 lines

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

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

Thanks!

-- Steve

Quoted 34 lines
---
 tracecmd/trace-split.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
tracecmd/trace-split.c +3 -7
index d27b3c65badc..6c8a774e13d0 100644
@@ -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);