Skip to contentSkip to conversation

migration/qemu-file: Fix maybe uninitialized on qemu_get_buffer_in_place()

PATCH In review Wainer dos Santos Moschetta 3 participants 6 messages Jan 28, 2021 – Feb 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 migration/qemu-file: Fix maybe uninitialized on qemu_get_buffer_in_place()

Fixed error when compiling migration/qemu-file.c with -Werror=maybe-uninitialized as shown here:

../migration/qemu-file.c: In function 'qemu_get_buffer_in_place':
../migration/qemu-file.c:604:18: error: 'src' may be used uninitialized in this function [-Werror=maybe-uninitialized]

  604 |             *buf = src;
      |             ~~~~~^~~~~

cc1: all warnings being treated as errors

---
Passed on CI: https://gitlab.com/wainersm/qemu/-/pipelines/247801576

 migration/qemu-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/qemu-file.c +1 -1
index be21518c57..d6e03dbc0e 100644
@@ -595,7 +595,7 @@ size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size)
 {
     if (size < IO_BUF_SIZE) {
         size_t res;
-        uint8_t *src;
+        uint8_t *src = NULL;
 
         res = qemu_peek_buffer(f, &src, size, 0);
 
Signature · 1 line
2.28.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · * Wainer dos Santos Moschetta ([email protected]) wrote:

Fixed error when compiling migration/qemu-file.c with -Werror=maybe-uninitialized as shown here:

../migration/qemu-file.c: In function 'qemu_get_buffer_in_place':
../migration/qemu-file.c:604:18: error: 'src' may be used uninitialized in this function [-Werror=maybe-uninitialized]

  604 |             *buf = src;
      |             ~~~~~^~~~~

cc1: all warnings being treated as errors

Yes, I think I had a discussion with someone about this recently but can't find it; the compiler is technically correct, but the only time it's unitialised is the case where it's result doesn't matter.

Still, to shut the compiler up:

Quoted 22 lines

---
Passed on CI: https://gitlab.com/wainersm/qemu/-/pipelines/247801576

 migration/qemu-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/qemu-file.c +1 -1
index be21518c57..d6e03dbc0e 100644
@@ -595,7 +595,7 @@ size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size)
 {
     if (size < IO_BUF_SIZE) {
         size_t res;
-        uint8_t *src;
+        uint8_t *src = NULL;
 
         res = qemu_peek_buffer(f, &src, size, 0);
 
Signature · 1 line
2.28.0
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#2 lore raw
Quoted 10 lines · Dr. David Alan Gilbert
Quoted 9 lines · * Wainer dos Santos Moschetta ([email protected]) wrote:

Fixed error when compiling migration/qemu-file.c with -Werror=maybe-uninitialized as shown here:

../migration/qemu-file.c: In function 'qemu_get_buffer_in_place':
../migration/qemu-file.c:604:18: error: 'src' may be used uninitialized in this function [-Werror=maybe-uninitialized]

  604 |             *buf = src;
      |             ~~~~~^~~~~

cc1: all warnings being treated as errors

Quoted 4 lines
Quoted 1 line

Yes, I think I had a discussion with someone about this recently but can't find it;

Maybe with Thomas, he reported that 2 years ago when building with -O3:
https://www.mail-archive.com/[email protected]/msg599522.html

Quoted 30 lines

the compiler is technically correct, but the only time it's unitialised is the case where it's result doesn't matter.

Still, to shut the compiler up:

Quoted 22 lines

---
Passed on CI: https://gitlab.com/wainersm/qemu/-/pipelines/247801576

 migration/qemu-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/qemu-file.c +1 -1
index be21518c57..d6e03dbc0e 100644
@@ -595,7 +595,7 @@ size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size)
 {
     if (size < IO_BUF_SIZE) {
         size_t res;
-        uint8_t *src;
+        uint8_t *src = NULL;
 
         res = qemu_peek_buffer(f, &src, size, 0);
 
Signature · 1 line
2.28.0
#3 lore raw

Hi,

Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Dr. David Alan Gilbert
Quoted 9 lines · * Wainer dos Santos Moschetta ([email protected]) wrote:

Fixed error when compiling migration/qemu-file.c with -Werror=maybe-uninitialized as shown here:

../migration/qemu-file.c: In function 'qemu_get_buffer_in_place':
../migration/qemu-file.c:604:18: error: 'src' may be used uninitialized in this function [-Werror=maybe-uninitialized]

   604 |             *buf = src;
       |             ~~~~~^~~~~

cc1: all warnings being treated as errors

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Yes, I think I had a discussion with someone about this recently but can't find it;

Maybe with Thomas, he reported that 2 years ago when building with -O3:
https://www.mail-archive.com/[email protected]/msg599522.html

I saw that error when compiling QEMU with -O3 as well.

Quoted 8 lines
Quoted 8 lines

the compiler is technically correct, but the only time it's unitialised is the case where it's result doesn't matter.

Still, to shut the compiler up:

Thanks David!

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines

---
Passed on CI: https://gitlab.com/wainersm/qemu/-/pipelines/247801576

  migration/qemu-file.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
migration/qemu-file.c +1 -1
index be21518c57..d6e03dbc0e 100644
@@ -595,7 +595,7 @@ size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size)
  {
      if (size < IO_BUF_SIZE) {
          size_t res;
-        uint8_t *src;
+        uint8_t *src = NULL;
 
          res = qemu_peek_buffer(f, &src, size, 0);
 
Signature · 1 line
2.28.0
#4 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 11 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:
Quoted 10 lines · Dr. David Alan Gilbert
Quoted 9 lines · * Wainer dos Santos Moschetta ([email protected]) wrote:

Fixed error when compiling migration/qemu-file.c with -Werror=maybe-uninitialized as shown here:

../migration/qemu-file.c: In function 'qemu_get_buffer_in_place':
../migration/qemu-file.c:604:18: error: 'src' may be used uninitialized in this function [-Werror=maybe-uninitialized]

  604 |             *buf = src;
      |             ~~~~~^~~~~

cc1: all warnings being treated as errors

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Yes, I think I had a discussion with someone about this recently but can't find it;

Maybe with Thomas, he reported that 2 years ago when building with -O3:
https://www.mail-archive.com/[email protected]/msg599522.html

I've got this vague memory I've had a conversation much much more recently; like in the last month or two but I can't find it.

Dave

Quoted 31 lines
Quoted 30 lines

the compiler is technically correct, but the only time it's unitialised is the case where it's result doesn't matter.

Still, to shut the compiler up:

Quoted 22 lines

---
Passed on CI: https://gitlab.com/wainersm/qemu/-/pipelines/247801576

 migration/qemu-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/qemu-file.c +1 -1
index be21518c57..d6e03dbc0e 100644
@@ -595,7 +595,7 @@ size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size)
 {
     if (size < IO_BUF_SIZE) {
         size_t res;
-        uint8_t *src;
+        uint8_t *src = NULL;
 
         res = qemu_peek_buffer(f, &src, size, 0);
 
Signature · 1 line
2.28.0
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#5 lore raw
In reply to Dr. David Alan Gilbert
Quoted 12 lines · * Dr. David Alan Gilbert ([email protected]) wrote:
Quoted 10 lines · * Wainer dos Santos Moschetta ([email protected]) wrote:

Fixed error when compiling migration/qemu-file.c with -Werror=maybe-uninitialized as shown here:

../migration/qemu-file.c: In function 'qemu_get_buffer_in_place':
../migration/qemu-file.c:604:18: error: 'src' may be used uninitialized in this function [-Werror=maybe-uninitialized]

  604 |             *buf = src;
      |             ~~~~~^~~~~

cc1: all warnings being treated as errors

Quoted 8 lines

Yes, I think I had a discussion with someone about this recently but can't find it; the compiler is technically correct, but the only time it's unitialised is the case where it's result doesn't matter.

Still, to shut the compiler up:

Queued

Quoted 27 lines
Quoted 23 lines

---
Passed on CI: https://gitlab.com/wainersm/qemu/-/pipelines/247801576

 migration/qemu-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/qemu-file.c +1 -1
index be21518c57..d6e03dbc0e 100644
@@ -595,7 +595,7 @@ size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size)
 {
     if (size < IO_BUF_SIZE) {
         size_t res;
-        uint8_t *src;
+        uint8_t *src = NULL;
 
         res = qemu_peek_buffer(f, &src, size, 0);
 
Signature · 1 line
2.28.0
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK