linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Ian Rogers <irogers@google.com>
Cc: linux-trace-devel@vger.kernel.org,
	Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
Subject: Re: [PATCH] trace-cmd: Fix use of uninitialized variable
Date: Tue, 15 Feb 2022 12:09:48 -0500	[thread overview]
Message-ID: <20220215120948.4bd0802b@gandalf.local.home> (raw)
In-Reply-To: <20220202214646.553872-1-irogers@google.com>

On Wed,  2 Feb 2022 13:46:46 -0800
Ian Rogers <irogers@google.com> 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]
>         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

> ---
>  lib/trace-cmd/trace-input.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
> index ecb5682..57bd4ee 100644
> --- a/lib/trace-cmd/trace-input.c
> +++ b/lib/trace-cmd/trace-input.c
> @@ -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)


  reply	other threads:[~2022-02-15 17:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-02 21:46 [PATCH] trace-cmd: Fix use of uninitialized variable Ian Rogers
2022-02-15 17:09 ` Steven Rostedt [this message]
2022-02-24 19:39   ` 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=20220215120948.4bd0802b@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=irogers@google.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=tz.stoyanov@gmail.com \
    /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 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).