Skip to contentSkip to conversation

tests/unit/test-block-iothread: fix maybe-uninitialized error on GCC 11

PATCH In review Emanuele Giuseppe Esposito 3 participants 3 messages Mar 19, 2021 – Mar 21, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/unit/test-block-iothread: fix maybe-uninitialized error on GCC 11

When building qemu with GCC 11, test-block-iothread produces the following warning:

../tests/unit/test-block-iothread.c:148:11: error: ‘buf’ may be used uninitialized [-Werror=maybe-uninitialized]

This is caused by buf[512] left uninitialized and passed to bdrv_save_vmstate() that expects a const uint8_t *, so the compiler assumes it will be read and expects the parameter to be initialized.

---
 tests/unit/test-block-iothread.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/unit/test-block-iothread.c +3 -3
index 3f866a35c6..8cf172cb7a 100644
@@ -89,7 +89,7 @@ static void test_sync_op_pread(BdrvChild *c)
 
 static void test_sync_op_pwrite(BdrvChild *c)
 {
-    uint8_t buf[512];
+    uint8_t buf[512] = { 0 };
     int ret;
 
     /* Success */
@@ -117,7 +117,7 @@ static void test_sync_op_blk_pread(BlockBackend *blk)
 
 static void test_sync_op_blk_pwrite(BlockBackend *blk)
 {
-    uint8_t buf[512];
+    uint8_t buf[512] = { 0 };
     int ret;
 
     /* Success */
@@ -141,7 +141,7 @@ static void test_sync_op_load_vmstate(BdrvChild *c)
 
 static void test_sync_op_save_vmstate(BdrvChild *c)
 {
-    uint8_t buf[512];
+    uint8_t buf[512] = { 0 };
     int ret;
 
     /* Error: Driver does not support snapshots */
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 39 lines · Emanuele Giuseppe Esposito

When building qemu with GCC 11, test-block-iothread produces the following warning:

../tests/unit/test-block-iothread.c:148:11: error: ‘buf’ may be used uninitialized [-Werror=maybe-uninitialized]

This is caused by buf[512] left uninitialized and passed to bdrv_save_vmstate() that expects a const uint8_t *, so the compiler assumes it will be read and expects the parameter to be initialized.

---
  tests/unit/test-block-iothread.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
tests/unit/test-block-iothread.c +2 -2
index 3f866a35c6..8cf172cb7a 100644
@@ -89,7 +89,7 @@ static void test_sync_op_pread(BdrvChild *c)
 
  static void test_sync_op_pwrite(BdrvChild *c)
  {
-    uint8_t buf[512];
+    uint8_t buf[512] = { 0 };
      int ret;
 
      /* Success */
@@ -117,7 +117,7 @@ static void test_sync_op_blk_pread(BlockBackend *blk)
 
  static void test_sync_op_blk_pwrite(BlockBackend *blk)
  {
-    uint8_t buf[512];
+    uint8_t buf[512] = { 0 };
      int ret;
 
      /* Success */

tests/unit/test-block-iothread.c static void test_sync_op_load_vmstate(BdrvChild *c) · line 147

Quoted 8 lines
tests/unit/test-block-iothread.c +1 -1
@@ -141,7 +141,7 @@ static void test_sync_op_load_vmstate(BdrvChild *c)
 
  static void test_sync_op_save_vmstate(BdrvChild *c)
  {
-    uint8_t buf[512];
+    uint8_t buf[512] = { 0 };
      int ret;
 
      /* Error: Driver does not support snapshots */
Reviewed-by on v1 1/1
#2 lore raw
In reply to Emanuele Giuseppe Esposito
Quoted 11 lines · Emanuele Giuseppe Esposito

When building qemu with GCC 11, test-block-iothread produces the following warning:

../tests/unit/test-block-iothread.c:148:11: error: ‘buf’ may be used uninitialized [-Werror=maybe-uninitialized]

This is caused by buf[512] left uninitialized and passed to bdrv_save_vmstate() that expects a const uint8_t *, so the compiler assumes it will be read and expects the parameter to be initialized.

Berto