Richard W.M. Jones
2019-Apr-24 20:31 UTC
[Libguestfs] [PATCH nbdkit] server: Initialize ‘buf’ to avoid GCC 9.0.1 warning.
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; | ^~~ --- server/protocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/protocol.c b/server/protocol.c index 6fd3b62..5033fd7 100644 --- a/server/protocol.c +++ b/server/protocol.c @@ -611,7 +611,7 @@ protocol_recv_request_send_reply (struct connection *conn) uint16_t cmd, flags; uint32_t magic, count, error = 0; uint64_t offset; - char *buf; + char *buf = NULL; CLEANUP_EXTENTS_FREE struct nbdkit_extents *extents = NULL; /* Read the request packet. */ -- 2.20.1
Eric Blake
2019-Apr-24 20:38 UTC
Re: [Libguestfs] [PATCH nbdkit] server: Initialize ‘buf’ to avoid GCC 9.0.1 warning.
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
Possibly Parallel Threads
- [PATCH nbdkit v2 2/2] server: Use a thread-local pread/pwrite buffer to avoid leaking heap data.
- Re: [PATCH nbdkit v2 2/2] server: Use a thread-local pread/pwrite buffer to avoid leaking heap data.
- [PATCH nbdkit v2 0/2] Be careful not to leak server heap memory to the client.
- [PATCH nbdkit 3/8] server: Implement Block Status requests to read allocation status.
- [PATCH nbdkit 0/2] Be careful not to leak heap memory to the client.