Skip to contentSkip to conversation

trace-cmd: Fix use of uninitialized variable

PATCH In review Ian Rogers 2 participants 3 messages Feb 2, 2022 – Feb 24, 2022

lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH 1/1 trace-cmd: Fix use of uninitialized variable

Caught by clang's -Wsometimes-uninitialized and accepting the suggested fix:

lib/trace-cmd/trace-input.c:4325:6: error: variable 'sec' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]

        if (handle->file_state >= start_state) {
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/trace-cmd/trace-input.c:4336:6: note: uninitialized use occurs here
        if (sec)
            ^~~
lib/trace-cmd/trace-input.c:4325:2: note: remove the 'if' if its condition is always true
        if (handle->file_state >= start_state) {
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/trace-cmd/trace-input.c:4311:26: note: initialize the variable 'sec' to silence this warning
        struct file_section *sec;
                                ^
                                 = NULL
---
 lib/trace-cmd/trace-input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/trace-cmd/trace-input.c +1 -1
index ecb5682..57bd4ee 100644
@@ -4308,7 +4308,7 @@ int tracecmd_copy_headers(struct tracecmd_input *handle, int fd,
 			  enum tracecmd_file_states start_state,
 			  enum tracecmd_file_states end_state)
 {
-	struct file_section *sec;
+	struct file_section *sec = NULL;
 	int ret;
 
 	if (!start_state)
Signature · 1 line
2.35.0.rc2.247.g8bbb082509-goog
#1 lore raw
Quoted 4 lines · On Wed, 2 Feb 2022 13:46:46 -0800 Ian Rogers <[email protected]> wrote:

Caught by clang's -Wsometimes-uninitialized and accepting the suggested fix:

lib/trace-cmd/trace-input.c:4325:6: error: variable 'sec' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]

Quoted 12 lines
        if (handle->file_state >= start_state) {
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/trace-cmd/trace-input.c:4336:6: note: uninitialized use occurs here
        if (sec)
            ^~~
lib/trace-cmd/trace-input.c:4325:2: note: remove the 'if' if its condition is always true
        if (handle->file_state >= start_state) {
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/trace-cmd/trace-input.c:4311:26: note: initialize the variable 'sec' to silence this warning
        struct file_section *sec;
                                ^
                                 = NULL

-ENOSOB

;-)

-- Steve

Quoted 17 lines
---
 lib/trace-cmd/trace-input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/trace-cmd/trace-input.c +1 -1
index ecb5682..57bd4ee 100644
@@ -4308,7 +4308,7 @@ int tracecmd_copy_headers(struct tracecmd_input *handle, int fd,
 			  enum tracecmd_file_states start_state,
 			  enum tracecmd_file_states end_state)
 {
-	struct file_section *sec;
+	struct file_section *sec = NULL;
 	int ret;
 
 	if (!start_state)
#2 lore raw
Quoted 3 lines · On Tue, 15 Feb 2022 12:09:48 -0500 Steven Rostedt <[email protected]> wrote:

-ENOSOB

;-)

So I applied this patch myself and gave a Reported-by to you, as it requires the author to have their SOB.

-- Steve