qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: pannengyuan@huawei.com
Cc: qemu-trivial@nongnu.org, Euler Robot <euler.robot@huawei.com>,
	qemu-devel@nongnu.org, qemu-block@nongnu.org,
	zhang.zhanghailiang@huawei.com
Subject: Re: [PATCH] nbd: fix uninitialized variable warning
Date: Tue, 7 Jan 2020 16:24:52 -0600	[thread overview]
Message-ID: <a67b1b6c-addf-da76-b8b3-8af0dd48a1d8@redhat.com> (raw)
In-Reply-To: <20200106015443.38540-1-pannengyuan@huawei.com>

On 1/5/20 7:54 PM, pannengyuan@huawei.com wrote:
> From: Pan Nengyuan <pannengyuan@huawei.com>
> 
> Fixes:
> /mnt/sdb/qemu/nbd/server.c: In function 'nbd_handle_request':
> /mnt/sdb/qemu/nbd/server.c:2313:9: error: 'ret' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>       int ret;
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>

False positive in the robot - I cannot see any path where ret is used 
uninitialized.  Closest might be the handling of NBD_CMD_BLOCK_STATUS, 
which looks like:

if (a || b) {
   if (a) {
     ret = ...;
     if (ret < 0) {
       return ret;
     }
   }
   if (b) {
     ret = ...;
     if (ret < 0) {
       return ret;
     }
   }
   return ret;
}

In fact, those 'if (ret < 0)' tests are pointless, since nothing else 
really happens before the final return ret.

If I'm right about this being what trips up the robot, does changing 'if 
(b)' into 'else' solve the problem, rather than adding an initializer? 
And if so, can we clean up the pointless code while at it?

> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> ---
>   nbd/server.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/nbd/server.c b/nbd/server.c
> index 24ebc1a805..7eb3de0842 100644
> --- a/nbd/server.c
> +++ b/nbd/server.c
> @@ -2310,7 +2310,7 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
>                                              NBDRequest *request,
>                                              uint8_t *data, Error **errp)
>   {
> -    int ret;
> +    int ret = 0;
>       int flags;
>       NBDExport *exp = client->exp;
>       char *msg;
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



  reply	other threads:[~2020-01-07 22:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-06  1:54 [PATCH] nbd: fix uninitialized variable warning pannengyuan
2020-01-07 22:24 ` Eric Blake [this message]
2020-01-08  2:05   ` Pan Nengyuan

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=a67b1b6c-addf-da76-b8b3-8af0dd48a1d8@redhat.com \
    --to=eblake@redhat.com \
    --cc=euler.robot@huawei.com \
    --cc=pannengyuan@huawei.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=zhang.zhanghailiang@huawei.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).