nbd: fix uninitialized variable warning
PATCH v2 1/1 nbd: fix uninitialized variable warning
../block/nbd.c: In function 'nbd_co_request':../block/nbd.c:745:8: error: 'local_reply.type' may be used uninitialized in this function [-Werror=maybe-uninitialized]
if (chunk->type == NBD_REPLY_TYPE_NONE) {
^
../block/nbd.c:710:14: note: 'local_reply.type' was declared here
NBDReply local_reply;
^~~~~~~~~~~
../block/nbd.c:710:14: error: 'local_reply.flags' may be used uninitialized in this function [-Werror=maybe-uninitialized]
../block/nbd.c:738:8: error: 'local_reply.<U4be0>.magic' may be used uninitialized in this function [-Werror=maybe-uninitialized]
if (nbd_reply_is_simple(reply) || s->quit) {
^
../block/nbd.c:710:14: note: 'local_reply.<U4be0>.magic' was declared here
NBDReply local_reply;
^~~~~~~~~~~cc1: all warnings being treated as errors
--- block/nbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/nbd.c +1 -1
@@ -707,7 +707,7 @@ static bool nbd_reply_chunk_iter_receive(BDRVNBDState *s, void **payload) {int ret, request_ret; -NBDReply local_reply; +NBDReply local_reply = {};NBDStructuredReplyChunk *chunk;Error *local_err =NULL ;if (s->quit) {
Signature · 1 line
2.22.0.428.g6d5b264208
I was writing on your v1 "it might be worth commenting this is when building with -O3"
This might be as easy as having the subject modified (by maintainer taking this patch?) as:
"fix uninitialized variable warning [when building with -O3]"
Quoted 37 lines · Marc-André Lureau
../block/nbd.c: In function 'nbd_co_request':../block/nbd.c:745:8: error: 'local_reply.type' may be used uninitialized in this function [-Werror=maybe-uninitialized]if (chunk->type == NBD_REPLY_TYPE_NONE) { ^ ../block/nbd.c:710:14: note: 'local_reply.type' was declared here NBDReply local_reply; ^~~~~~~~~~~ ../block/nbd.c:710:14: error: 'local_reply.flags' may be used uninitialized in this function [-Werror=maybe-uninitialized] ../block/nbd.c:738:8: error: 'local_reply.<U4be0>.magic' may be used uninitialized in this function [-Werror=maybe-uninitialized] if (nbd_reply_is_simple(reply) || s->quit) { ^ ../block/nbd.c:710:14: note: 'local_reply.<U4be0>.magic' was declared here NBDReply local_reply; ^~~~~~~~~~~cc1: all warnings being treated as errors
Reported-by Thomas Huth <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>--- block/nbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/nbd.c +1
-1@@ -707,7 +707,7 @@ static bool nbd_reply_chunk_iter_receive(BDRVNBDState *s, void **payload) {int ret, request_ret; -NBDReply local_reply; +NBDReply local_reply = {};NBDStructuredReplyChunk *chunk;Error *local_err =NULL ;if (s->quit) {
Quoted 8 lines · Philippe Mathieu-Daudé
I was writing on your v1 "it might be worth commenting this is when building with -O3"
This might be as easy as having the subject modified (by maintainer taking this patch?) as:
"fix uninitialized variable warning [when building with -O3]"
I can do a touchup (probably to the commit body, rather than the subject).
Quoted 5 lines
Quoted 5 lines
cc1: all warnings being treated as errors
Reported-by Thomas Huth <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thanks; will queue through my NBD tree.
Quoted 4 lines
Quoted 4 lines
--- block/nbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 10 lines
block/nbd.c static bool nbd_reply_chunk_iter_receive(BDRVNBDState *s, · line 710
Quoted 10 lines
block/nbd.c +1
-1@@ -707,7 +707,7 @@ static bool nbd_reply_chunk_iter_receive(BDRVNBDState *s, void **payload) {int ret, request_ret; -NBDReply local_reply; +NBDReply local_reply = {};
Relies on the gcc extension rather than the idiomatic C spelling of {0} (but we rely on it elsewhere, in part because some versions of clang are buggy on incorrectly warning about the idiomatic spelling, so nothing new)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Quoted 14 lines · Marc-André Lureau
../block/nbd.c: In function 'nbd_co_request':../block/nbd.c:745:8: error: 'local_reply.type' may be used uninitialized in this function [-Werror=maybe-uninitialized]if (chunk->type == NBD_REPLY_TYPE_NONE) { ^ ../block/nbd.c:710:14: note: 'local_reply.type' was declared here NBDReply local_reply; ^~~~~~~~~~~ ../block/nbd.c:710:14: error: 'local_reply.flags' may be used uninitialized in this function [-Werror=maybe-uninitialized] ../block/nbd.c:738:8: error: 'local_reply.<U4be0>.magic' may be used uninitialized in this function [-Werror=maybe-uninitialized] if (nbd_reply_is_simple(reply) || s->quit) { ^ ../block/nbd.c:710:14: note: 'local_reply.<U4be0>.magic' was declared here NBDReply local_reply; ^~~~~~~~~~~
Quoted 8 lines
cc1: all warnings being treated as errors
Reported-by Thomas Huth <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>--- block/nbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Actually, since this patch didn't fix all the cases of use of an uninit variable, I'm wondering if this one-liner would be a better patch for the issue (that is, fix it so that nbd_co_receive_one_chunk never leaves reply uninit, rather than chasing down which callers might need init), and with a perk of not relying on a gcc extension:
block/nbd.c +0 -0
@@ -640,6 +640,7 @@ static coroutine_fn int nbd_co_receive_one_chunk( request_ret, qiov, payload,
errp);
if (ret < 0) {
+ memset(reply, 0, sizeof *reply);
s->quit = true;
} else {
/* For assert at loop start in nbd_connection_entry */Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org