diff mbox

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

Message ID 1364496184-11994-1-git-send-email-peter.maydell@linaro.org
State Accepted
Commit c31bc98e3bcf52fe1cd4b9b7a70869330eae80ea
Headers show

Commit Message

Peter Maydell March 28, 2013, 6:43 p.m. UTC
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'.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
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(+)

Comments

Michael Walle March 28, 2013, 6:50 p.m. UTC | #1
Am Donnerstag 28 März 2013, 19:43:04 schrieb Peter Maydell:
> 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'.)
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> 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(+)
> 
> diff --git a/hw/milkymist-softusb.c b/hw/milkymist-softusb.c
> index d911686..9f83209 100644
> --- a/hw/milkymist-softusb.c
> +++ b/hw/milkymist-softusb.c
> @@ -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;
>      }

Acked-By: Michael Walle <michael@walle.cc>
Anthony Liguori April 1, 2013, 8:36 p.m. UTC | #2
Applied.  Thanks.

Regards,

Anthony Liguori
diff mbox

Patch

diff --git a/hw/milkymist-softusb.c b/hw/milkymist-softusb.c
index d911686..9f83209 100644
--- a/hw/milkymist-softusb.c
+++ b/hw/milkymist-softusb.c
@@ -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;
     }