qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/4] nbd: silence maybe-uninitialized warnings


From: Eric Blake
Subject: Re: [PATCH 2/4] nbd: silence maybe-uninitialized warnings
Date: Wed, 30 Sep 2020 12:19:39 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0

On 9/30/20 10:58 AM, Christian Borntraeger wrote:
> gcc 10 from Fedora 32 gives me:
> 
> Compiling C object libblock.fa.p/nbd_server.c.o
> ../nbd/server.c: In function ‘nbd_co_client_start’:
> ../nbd/server.c:625:14: error: ‘namelen’ may be used uninitialized in this 
> function [-Werror=maybe-uninitialized]
>   625 |         rc = nbd_negotiate_send_info(client, NBD_INFO_NAME, namelen, 
> name,
>       |              
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   626 |                                      errp);
>       |                                      ~~~~~
> ../nbd/server.c:564:14: note: ‘namelen’ was declared here
>   564 |     uint32_t namelen;
>       |              ^~~~~~~
> cc1: all warnings being treated as errors
> 
> As I cannot see how this can happen, let uns silence the warning.

gcc is smart enough to see that nbd_opt_read_name(... &namelen), which
is the only use of namelen between declaration and use, does not always
initialize namelen; but fails to see we also exit this function early in
the same conditions when nbd_opt_read_name left namelen uninit.  The
workaround is fine.

Reviewed-by: Eric Blake <eblake@redhat.com>

I'm happy for this to go in through the trivial tree, but I'll also
queue it on my NBD tree if that is ready first.


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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]