[Libguestfs] [PATCH nbdkit] server: Initialize ‘buf’ to avoid GCC 9.0.1 warning.

Eric Blake eblake at redhat.com
Wed Apr 24 20:38:36 UTC 2019


On 4/24/19 3:31 PM, Richard W.M. Jones wrote:
> GCC 9.0.1 isn't smart enough to work out that buf is initialized on
> all the relevant paths that lead to backend->pwrite being called.  By
> initializing it we can avoid the warning.
> 
> protocol.c: In function ‘protocol_recv_request_send_reply’:
> protocol.c:241:9: error: ‘buf’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>   241 |     if (backend->pwrite (backend, conn, buf, count, offset, f, &err) == -1)
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> protocol.c:614:9: note: ‘buf’ was declared here
>   614 |   char *buf;
>       |         ^~~

Wow - cross-function inlining evident in that error message. I agree
that it's a false positive; without your patch, buf can be passed to
handle_request() uninitialized, but never in the NBD_CMD_WRITE case,
even if the compiler can't spot that.

ACK.

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190424/aa4155ec/attachment.sig>


More information about the Libguestfs mailing list