Skip to contentSkip to conversation

block: fix build waring

PATCH In review Zhiwei Jiang 3 participants 3 messages Jun 13, 2021 – Jun 14, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: fix build waring

when i compile this file with some error message ../block.c: In function ‘bdrv_replace_node_common’:
../block.c:4903:9: error: ‘to_cow_parent’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

         bdrv_remove_filter_or_cow_child(to_cow_parent, tran);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +1 -1
index 3f456892d0..08f29e6b65 100644
@@ -4866,7 +4866,7 @@ static int bdrv_replace_node_common(BlockDriverState *from,
     Transaction *tran = tran_new();
     g_autoptr(GHashTable) found = NULL;
     g_autoptr(GSList) refresh_list = NULL;
-    BlockDriverState *to_cow_parent;
+    BlockDriverState *to_cow_parent = NULL;
     int ret;
 
     if (detach_subchain) {
Signature · 1 line
2.25.1
#1 lore raw
Quoted 8 lines · Zhiwei Jiang

when i compile this file with some error message ../block.c: In function ‘bdrv_replace_node_common’:
../block.c:4903:9: error: ‘to_cow_parent’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

         bdrv_remove_filter_or_cow_child(to_cow_parent, tran);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

Could you provide the compiler version when reporting fails-to-compile issues, please? (This is useful for us to get an idea of whether the problem is an old compiler that's not smart enough to figure out that something's not used uninitialized, or a new compiler that does more checking.)

thanks
-- PMM

#2 lore raw
In reply to Zhiwei Jiang

On Sun, Jun 13, 2021 at 05:38:21PM +0800, Zhiwei Jiang wrote:

In the subject, s/waring/warning/

Quoted 4 lines

when i compile this file with some error message ../block.c: In function ‘bdrv_replace_node_common’:
../block.c:4903:9: error: ‘to_cow_parent’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

Quoted 8 lines
         bdrv_remove_filter_or_cow_child(to_cow_parent, tran);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

This looks identical to
https://lists.gnu.org/archive/html/qemu-devel/2021-05/msg01229.html
which has a more complete commit message and is already on Kevin's tree for an upcoming pull request.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org