diff mbox

lm32: milkymist-tmu2: fix another integer overflow

Message ID 1483724714-5469-1-git-send-email-peter.maydell@linaro.org
State New
Headers show

Commit Message

Peter Maydell Jan. 6, 2017, 5:45 p.m. UTC
Don't truncate the multiplication and do a 64 bit one instead
because the result is stored in a 64 bit variable.

This fixes a similar coverity warning to commit 237a8650d640,
in a similar way, and is the other half of the fix for
coverity CID 1167561.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/display/milkymist-tmu2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Michael Walle Jan. 6, 2017, 7:28 p.m. UTC | #1
Am 6. Januar 2017 18:45:14 MEZ schrieb Peter Maydell <peter.maydell@linaro.org>:
>Don't truncate the multiplication and do a 64 bit one instead
>because the result is stored in a 64 bit variable.
>
>This fixes a similar coverity warning to commit 237a8650d640,
>in a similar way, and is the other half of the fix for
>coverity CID 1167561.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Acked-by: Michael Walle <michael@walle.cc>

>---
> hw/display/milkymist-tmu2.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/hw/display/milkymist-tmu2.c b/hw/display/milkymist-tmu2.c
>index 5c666f9..920374b 100644
>--- a/hw/display/milkymist-tmu2.c
>+++ b/hw/display/milkymist-tmu2.c
>@@ -257,7 +257,7 @@ static void tmu2_start(MilkymistTMU2State *s)
>     glColor4f(m, m, m, (float)(s->regs[R_ALPHA] + 1) / 64.0f);
> 
>     /* Read the QEMU dest. framebuffer into the OpenGL framebuffer */
>-    fb_len = 2 * s->regs[R_DSTHRES] * s->regs[R_DSTVRES];
>+    fb_len = 2ULL * s->regs[R_DSTHRES] * s->regs[R_DSTVRES];
>     fb = cpu_physical_memory_map(s->regs[R_DSTFBUF], &fb_len, 0);
>     if (fb == NULL) {
>         glDeleteTextures(1, &texture);
Michael Tokarev Jan. 12, 2017, 11:01 a.m. UTC | #2
06.01.2017 20:45, Peter Maydell wrote:
> Don't truncate the multiplication and do a 64 bit one instead
> because the result is stored in a 64 bit variable.
> 
> This fixes a similar coverity warning to commit 237a8650d640,
> in a similar way, and is the other half of the fix for
> coverity CID 1167561.

Applied to -trivial, thanks!

/mjt
diff mbox

Patch

diff --git a/hw/display/milkymist-tmu2.c b/hw/display/milkymist-tmu2.c
index 5c666f9..920374b 100644
--- a/hw/display/milkymist-tmu2.c
+++ b/hw/display/milkymist-tmu2.c
@@ -257,7 +257,7 @@  static void tmu2_start(MilkymistTMU2State *s)
     glColor4f(m, m, m, (float)(s->regs[R_ALPHA] + 1) / 64.0f);
 
     /* Read the QEMU dest. framebuffer into the OpenGL framebuffer */
-    fb_len = 2 * s->regs[R_DSTHRES] * s->regs[R_DSTVRES];
+    fb_len = 2ULL * s->regs[R_DSTHRES] * s->regs[R_DSTVRES];
     fb = cpu_physical_memory_map(s->regs[R_DSTFBUF], &fb_len, 0);
     if (fb == NULL) {
         glDeleteTextures(1, &texture);