block-qdict: Fix -Werror=maybe-uninitialized build failure
PATCH 1/1 block-qdict: Fix -Werror=maybe-uninitialized build failure
Building QEMU on Fedora 37 (Rawhide Prerelease) ppc64le failed with the following error:
$ ../configure --prefix=/usr/local/qemu-disabletcg --target-list=ppc-softmmu,ppc64-softmmu --disable-tcg --disable-linux-user
...
$ make -j$(nproc)
...
FAILED: libqemuutil.a.p/qobject_block-qdict.c.o
cc -m64 -mlittle-endian -Ilibqemuutil.a.p -I. -I.. -Isubprojects/libvhost-user -I../subprojects/libvhost-user -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/lib
mount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -I/usr/include/p11-kit-1 -I/usr/include/pixman-1 -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -isystem /root/qemu/linux-headers -isystem linux-headers -iquote
. -iquote /root/qemu -iquote /root/qemu/include -iquote /root/qemu/disas/libvixl -pthread -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite
-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-label
s -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -fstack-protector-strong -fPIE -MD -MQ libqemuutil.a.p/qobject_block-qdict.c.o -MF libqemuutil.a.p/qobject_block-qdict.c.o.d -
o libqemuutil.a.p/qobject_block-qdict.c.o -c ../qobject/block-qdict.c
In file included from /root/qemu/include/qapi/qmp/qdict.h:16,
from /root/qemu/include/block/qdict.h:13,
from ../qobject/block-qdict.c:11:
/root/qemu/include/qapi/qmp/qobject.h: In function ‘qdict_array_split’:
/root/qemu/include/qapi/qmp/qobject.h:49:17: error: ‘subqdict’ may be used uninitialized [-Werror=maybe-uninitialized]
49 | typeof(obj) _obj = (obj); \
| ^~~~
../qobject/block-qdict.c:227:16: note: ‘subqdict’ declared here
227 | QDict *subqdict;
| ^~~~~~~~
cc1: all warnings being treated as errorsFix build failure by initializing the QDict variable with NULL.
--- qobject/block-qdict.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qobject/block-qdict.c +1 -1
@@ -224,7 +224,7 @@ void qdict_array_split(QDict *src, QList **dst)for (i =0 ; i <UINT_MAX ; i++) {QObject *subqobj;bool is_subqdict; -QDict *subqdict; +QDict *subqdict =NULL ;char indexstr[32 ], prefix[32 ];size_t snprintf_ret;
Signature · 1 line
2.35.1
Quoted 26 lines · Murilo Opsfelder Araujo
Building QEMU on Fedora 37 (Rawhide Prerelease) ppc64le failed with the following error:
$ ../configure --prefix=/usr/local/qemu-disabletcg --target-list=ppc-softmmu,ppc64-softmmu --disable-tcg --disable-linux-user ... $ make -j$(nproc) ... FAILED: libqemuutil.a.p/qobject_block-qdict.c.o cc -m64 -mlittle-endian -Ilibqemuutil.a.p -I. -I.. -Isubprojects/libvhost-user -I../subprojects/libvhost-user -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/lib mount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -I/usr/include/p11-kit-1 -I/usr/include/pixman-1 -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -isystem /root/qemu/linux-headers -isystem linux-headers -iquote . -iquote /root/qemu -iquote /root/qemu/include -iquote /root/qemu/disas/libvixl -pthread -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite -strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-label s -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -fstack-protector-strong -fPIE -MD -MQ libqemuutil.a.p/qobject_block-qdict.c.o -MF libqemuutil.a.p/qobject_block-qdict.c.o.d - o libqemuutil.a.p/qobject_block-qdict.c.o -c ../qobject/block-qdict.c In file included from /root/qemu/include/qapi/qmp/qdict.h:16, from /root/qemu/include/block/qdict.h:13, from ../qobject/block-qdict.c:11: /root/qemu/include/qapi/qmp/qobject.h: In function ‘qdict_array_split’: /root/qemu/include/qapi/qmp/qobject.h:49:17: error: ‘subqdict’ may be used uninitialized [-Werror=maybe-uninitialized] 49 | typeof(obj) _obj = (obj); \ | ^~~~ ../qobject/block-qdict.c:227:16: note: ‘subqdict’ declared here 227 | QDict *subqdict; | ^~~~~~~~ cc1: all warnings being treated as errors
Quoted 7 lines
Fix build failure by initializing the QDict variable with NULL.
Signed-off-by Murilo Opsfelder Araujo <[email protected]>Cc Kevin Wolf <[email protected]>Cc Hanna Reitz <[email protected]>Cc Markus Armbruster <[email protected]>---
Quoted 16 lines
qobject/block-qdict.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)qobject/block-qdict.c +1
-1@@ -224,7 +224,7 @@ void qdict_array_split(QDict *src, QList **dst)for (i =0 ; i <UINT_MAX ; i++) {QObject *subqobj;bool is_subqdict; -QDict *subqdict; +QDict *subqdict =NULL ;char indexstr[32 ], prefix[32 ];size_t snprintf_ret;
Quoted 41 lines · Murilo Opsfelder Araujo
Building QEMU on Fedora 37 (Rawhide Prerelease) ppc64le failed with the following error:
$ ../configure --prefix=/usr/local/qemu-disabletcg --target-list=ppc-softmmu,ppc64-softmmu --disable-tcg --disable-linux-user ... $ make -j$(nproc) ... FAILED: libqemuutil.a.p/qobject_block-qdict.c.o cc -m64 -mlittle-endian -Ilibqemuutil.a.p -I. -I.. -Isubprojects/libvhost-user -I../subprojects/libvhost-user -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/lib mount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -I/usr/include/p11-kit-1 -I/usr/include/pixman-1 -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -isystem /root/qemu/linux-headers -isystem linux-headers -iquote . -iquote /root/qemu -iquote /root/qemu/include -iquote /root/qemu/disas/libvixl -pthread -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite -strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-label s -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -fstack-protector-strong -fPIE -MD -MQ libqemuutil.a.p/qobject_block-qdict.c.o -MF libqemuutil.a.p/qobject_block-qdict.c.o.d - o libqemuutil.a.p/qobject_block-qdict.c.o -c ../qobject/block-qdict.c In file included from /root/qemu/include/qapi/qmp/qdict.h:16, from /root/qemu/include/block/qdict.h:13, from ../qobject/block-qdict.c:11: /root/qemu/include/qapi/qmp/qobject.h: In function ‘qdict_array_split’: /root/qemu/include/qapi/qmp/qobject.h:49:17: error: ‘subqdict’ may be used uninitialized [-Werror=maybe-uninitialized] 49 | typeof(obj) _obj = (obj); \ | ^~~~ ../qobject/block-qdict.c:227:16: note: ‘subqdict’ declared here 227 | QDict *subqdict; | ^~~~~~~~ cc1: all warnings being treated as errorsFix build failure by initializing the QDict variable with NULL.
Signed-off-by Murilo Opsfelder Araujo <[email protected]>Cc Kevin Wolf <[email protected]>Cc Hanna Reitz <[email protected]>Cc Markus Armbruster <[email protected]>--- qobject/block-qdict.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)qobject/block-qdict.c +0
-0
qobject/block-qdict.c void qdict_array_split(QDict *src, QList **dst) · line 229
Quoted 7 lines
qobject/block-qdict.c +1
-1@@ -224,7 +224,7 @@ void qdict_array_split(QDict *src, QList **dst)for (i =0 ; i <UINT_MAX ; i++) {QObject *subqobj;bool is_subqdict; -QDict *subqdict; +QDict *subqdict =NULL ;char indexstr[32 ], prefix[32 ];size_t snprintf_ret;
The compiler's warning is actually spurious. Your patch is the minimally invasive way to shut it up. But I wonder whether we can make the code clearer instead. Let's have a look:
/*
* There may be either a single subordinate object (named
* "%u") or multiple objects (each with a key prefixed "%u."),
* but not both.
*/
if (!subqobj == !is_subqdict) {
break;Because of this, ...
}
if (is_subqdict) {... subqobj is non-null here, and ...
qdict_extract_subqdict(src, &subqdict, prefix);
assert(qdict_size(subqdict) > 0);
} else {... null here.
qobject_ref(subqobj);
qdict_del(src, indexstr);
}
qlist_append_obj(*dst, subqobj ?: QOBJECT(subqdict));What about this:
if (is_subqdict) {
qdict_extract_subqdict(src, &subqdict, prefix);
assert(qdict_size(subqdict) > 0);
qlist_append_obj(*dst, subqobj);
} else {
qobject_ref(subqobj);
qdict_del(src, indexstr);
qlist_append_obj(*dst, QOBJECT(subqdict));
}Hi, Markus.
Quoted 85 lines · Markus Armbruster
Quoted 41 lines · Murilo Opsfelder Araujo
Building QEMU on Fedora 37 (Rawhide Prerelease) ppc64le failed with the following error:
$ ../configure --prefix=/usr/local/qemu-disabletcg --target-list=ppc-softmmu,ppc64-softmmu --disable-tcg --disable-linux-user ... $ make -j$(nproc) ... FAILED: libqemuutil.a.p/qobject_block-qdict.c.o cc -m64 -mlittle-endian -Ilibqemuutil.a.p -I. -I.. -Isubprojects/libvhost-user -I../subprojects/libvhost-user -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/lib mount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -I/usr/include/p11-kit-1 -I/usr/include/pixman-1 -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -isystem /root/qemu/linux-headers -isystem linux-headers -iquote . -iquote /root/qemu -iquote /root/qemu/include -iquote /root/qemu/disas/libvixl -pthread -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite -strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-label s -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -fstack-protector-strong -fPIE -MD -MQ libqemuutil.a.p/qobject_block-qdict.c.o -MF libqemuutil.a.p/qobject_block-qdict.c.o.d - o libqemuutil.a.p/qobject_block-qdict.c.o -c ../qobject/block-qdict.c In file included from /root/qemu/include/qapi/qmp/qdict.h:16, from /root/qemu/include/block/qdict.h:13, from ../qobject/block-qdict.c:11: /root/qemu/include/qapi/qmp/qobject.h: In function ‘qdict_array_split’: /root/qemu/include/qapi/qmp/qobject.h:49:17: error: ‘subqdict’ may be used uninitialized [-Werror=maybe-uninitialized] 49 | typeof(obj) _obj = (obj); \ | ^~~~ ../qobject/block-qdict.c:227:16: note: ‘subqdict’ declared here 227 | QDict *subqdict; | ^~~~~~~~ cc1: all warnings being treated as errorsFix build failure by initializing the QDict variable with NULL.
Signed-off-by Murilo Opsfelder Araujo <[email protected]>Cc Kevin Wolf <[email protected]>Cc Hanna Reitz <[email protected]>Cc Markus Armbruster <[email protected]>--- qobject/block-qdict.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)qobject/block-qdict.c +0
-0qobject/block-qdict.c void qdict_array_split(QDict *src, QList **dst) · line 229
Quoted 7 lines
qobject/block-qdict.c +1
-1@@ -224,7 +224,7 @@ void qdict_array_split(QDict *src, QList **dst)for (i =0 ; i <UINT_MAX ; i++) {QObject *subqobj;bool is_subqdict; -QDict *subqdict; +QDict *subqdict =NULL ;char indexstr[32 ], prefix[32 ];size_t snprintf_ret;The compiler's warning is actually spurious. Your patch is the minimally invasive way to shut it up. But I wonder whether we can make the code clearer instead. Let's have a look:
/* * There may be either a single subordinate object (named * "%u") or multiple objects (each with a key prefixed "%u."), * but not both. */ if (!subqobj == !is_subqdict) { break;Because of this, ...
} if (is_subqdict) {... subqobj is non-null here, and ...
qdict_extract_subqdict(src, &subqdict, prefix); assert(qdict_size(subqdict) > 0); } else {... null here.
qobject_ref(subqobj); qdict_del(src, indexstr); } qlist_append_obj(*dst, subqobj ?: QOBJECT(subqdict));What about this:
Quoted 10 lines
if (is_subqdict) {
qdict_extract_subqdict(src, &subqdict, prefix);
assert(qdict_size(subqdict) > 0);
qlist_append_obj(*dst, subqobj);
} else {
qobject_ref(subqobj);
qdict_del(src, indexstr);
qlist_append_obj(*dst, QOBJECT(subqdict));
}The logic looks inverted but I think I got what you meant.
I've sent a v2 with changes that made the compiler happy and also passed check-unit tests.
Thank you!
Signature · 1 line
Murilo