]> git.proxmox.com Git - mirror_qemu.git/commitdiff
hw/ide/ahci.c: Fix shift left into sign bit
authorPeter Maydell <peter.maydell@linaro.org>
Fri, 16 Oct 2015 16:19:35 +0000 (17:19 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Sun, 18 Oct 2015 10:00:40 +0000 (11:00 +0100)
Avoid undefined behaviour from shifting left into the sign bit:

hw/ide/ahci.c:551:36: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'

(Unfortunately C's promotion rules mean that in the expression
"some_uint8_t_variable << 24" the LHS gets promoted to signed
int before shifting.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: John Snow <jsnow@redhat.com>
hw/ide/ahci.c

index 796be1563532243b7dda8ccaded5290194efa33f..21f76ed86e4370f3b75d3814f707c18e9d91f133 100644 (file)
@@ -548,7 +548,7 @@ static void ahci_init_d2h(AHCIDevice *ad)
         ad->init_d2h_sent = true;
         /* We're emulating receiving the first Reg H2D Fis from the device;
          * Update the SIG register, but otherwise proceed as normal. */
-        pr->sig = (ide_state->hcyl << 24) |
+        pr->sig = ((uint32_t)ide_state->hcyl << 24) |
             (ide_state->lcyl << 16) |
             (ide_state->sector << 8) |
             (ide_state->nsector & 0xFF);