Skip to contentSkip to conversation

target-i386: Fix signedness of MSR_IA32_APICBASE_BASE

PATCH In review Eduardo Habkost 2 participants 2 messages May 29, 2015 – Jun 2, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-i386: Fix signedness of MSR_IA32_APICBASE_BASE

Existing definition triggers the following when using clang -fsanitize=undefined:

hw/intc/apic_common.c:314:55: runtime error: left shift of 1048575 by 12
places cannot be represented in type 'int'

Fix it so we won't try to shift a 1 to the sign bit of a signed integer.

---
 target-i386/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/cpu.h +1 -1
index 4ee12ca..26182bd 100644
@@ -305,7 +305,7 @@
 #define MSR_IA32_APICBASE               0x1b
 #define MSR_IA32_APICBASE_BSP           (1<<8)
 #define MSR_IA32_APICBASE_ENABLE        (1<<11)
-#define MSR_IA32_APICBASE_BASE          (0xfffff<<12)
+#define MSR_IA32_APICBASE_BASE          (0xfffffU<<12)
 #define MSR_IA32_FEATURE_CONTROL        0x0000003a
 #define MSR_TSC_ADJUST                  0x0000003b
 #define MSR_IA32_TSCDEADLINE            0x6e0
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · On Fri, 29 May 2015 16:52:34 -0300 Eduardo Habkost <[email protected]> wrote:

Existing definition triggers the following when using clang -fsanitize=undefined:

hw/intc/apic_common.c:314:55: runtime error: left shift of 1048575 by 12
places cannot be represented in type 'int'

Fix it so we won't try to shift a 1 to the sign bit of a signed integer.

Quoted 17 lines
---
 target-i386/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/cpu.h +1 -1
index 4ee12ca..26182bd 100644
@@ -305,7 +305,7 @@
 #define MSR_IA32_APICBASE               0x1b
 #define MSR_IA32_APICBASE_BSP           (1<<8)
 #define MSR_IA32_APICBASE_ENABLE        (1<<11)
-#define MSR_IA32_APICBASE_BASE          (0xfffff<<12)
+#define MSR_IA32_APICBASE_BASE          (0xfffffU<<12)
 #define MSR_IA32_FEATURE_CONTROL        0x0000003a
 #define MSR_TSC_ADJUST                  0x0000003b
 #define MSR_IA32_TSCDEADLINE            0x6e0