hw/misc: mips_itu: Fix 32/64 bit issue in a line involving shift operator
authorAleksandar Markovic <amarkovic@wavecomp.com>
Mon, 18 Feb 2019 07:32:48 +0000 (08:32 +0100)
committerAleksandar Markovic <amarkovic@wavecomp.com>
Thu, 21 Feb 2019 18:36:47 +0000 (19:36 +0100)
Fix 32/64 bit issue in a line involving shift operator. "1 << ..."
calculation of size is done as a 32-bit signed integer which may
then be unintentionally sign-extended into the 64-bit result. The
problem was discovered by Coverity (CID 1398648). Using "1ULL"
instead of "1" on the LHS of the shift fixes this problem.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Aleksandar Markovic <amarkovic@wavecomp.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
hw/misc/mips_itu.c

index 1257d8fce622eee20e1bc75634bbae5763cf3917..3afdbe69c6bd351cee07d3fff1fc2c510de36414 100644 (file)
@@ -94,7 +94,7 @@ void itc_reconfigure(MIPSITUState *tag)
 
     if (tag->saar_present) {
         address = ((*(uint64_t *) tag->saar) & 0xFFFFFFFFE000ULL) << 4;
-        size = 1 << ((*(uint64_t *) tag->saar >> 1) & 0x1f);
+        size = 1ULL << ((*(uint64_t *) tag->saar >> 1) & 0x1f);
         is_enabled = *(uint64_t *) tag->saar & 1;
     }