Skip to contentSkip to conversation

hw/milkymist-softusb: set buffer in softusb_read_{dmem, pmem} error path

PATCH Applied Peter Maydell 3 participants 3 messages Mar 28, 2013 – Apr 1, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/milkymist-softusb: set buffer in softusb_read_{dmem, pmem} error path

Make sure we set the buffer to something in the softusb_read_{dmem,pmem} error paths, since the caller will use the buffer unconditionally. (Newer gcc is smart enough to spot this and complain about 'may be used uninitialized'.)

---
This needs to be applied before the 'drop sysbus_add_mem' patchset to fix a compilation failure with newer gcc. That patchset should apply after this without needing rebase, I think.

 hw/milkymist-softusb.c |    2 ++
 1 file changed, 2 insertions(+)
hw/milkymist-softusb.c +2 -0
index d911686..9f83209 100644
@@ -131,6 +131,7 @@ static inline void softusb_read_dmem(MilkymistSoftUsbState *s,
     if (offset + len >= s->dmem_size) {
         error_report("milkymist_softusb: read dmem out of bounds "
                 "at offset 0x%x, len %d", offset, len);
+        memset(buf, 0, len);
         return;
     }
 
@@ -155,6 +156,7 @@ static inline void softusb_read_pmem(MilkymistSoftUsbState *s,
     if (offset + len >= s->pmem_size) {
         error_report("milkymist_softusb: read pmem out of bounds "
                 "at offset 0x%x, len %d", offset, len);
+        memset(buf, 0, len);
         return;
     }
 
Signature · 1 line
1.7.9.5
Acked-by on v1 1/1
#1 lore raw

Am Donnerstag 28 März 2013, 19:43:04 schrieb Peter Maydell:

Quoted 32 lines

Make sure we set the buffer to something in the softusb_read_{dmem,pmem} error paths, since the caller will use the buffer unconditionally. (Newer gcc is smart enough to spot this and complain about 'may be used uninitialized'.)

---
This needs to be applied before the 'drop sysbus_add_mem' patchset to fix a compilation failure with newer gcc. That patchset should apply after this without needing rebase, I think.

 hw/milkymist-softusb.c |    2 ++
 1 file changed, 2 insertions(+)
hw/milkymist-softusb.c +0 -0
index d911686..9f83209 100644
@@ -131,6 +131,7 @@ static inline void

softusb_read_dmem(MilkymistSoftUsbState *s, if (offset + len >= s->dmem_size) {
error_report("milkymist_softusb: read dmem out of bounds "
"at offset 0x%x, len %d", offset, len);

hw/milkymist-softusb.c +1 -0
+        memset(buf, 0, len);
         return;
     }
@@ -155,6 +156,7 @@ static inline void

softusb_read_pmem(MilkymistSoftUsbState *s, if (offset + len >= s->pmem_size) {
error_report("milkymist_softusb: read pmem out of bounds "
"at offset 0x%x, len %d", offset, len);

Quoted 3 lines
+        memset(buf, 0, len);
         return;
     }