Skip to contentSkip to conversation

hw/core: Fix wrong left shift (build regression)

PATCH In review Stefan Weil 2 participants 2 messages Jul 31, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/core: Fix wrong left shift (build regression)

Shifting a long int (32 bit) by 40 bit positions won't work. Compiler message:

hw/core/qdev-properties.c: In function ‘print_size’:
hw/core/qdev-properties.c:1180:5: warning: left shift count >= width of type

---
 hw/core/qdev-properties.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/qdev-properties.c +1 -1
index 8d43a8d..e82ab87 100644
@@ -1177,7 +1177,7 @@ static int print_size(DeviceState *dev, Property *prop, char *dest, size_t len)
     int i = 0;
     uint64_t div;
 
-    for (div = (long int)1 << 40; !(*ptr / div) ; div >>= 10) {
+    for (div = 1ULL << 40; !(*ptr / div); div >>= 10) {
         i++;
     }
     return snprintf(dest, len, "%0.03f%c", (double)*ptr/div, suffixes[i]);
Signature · 1 line
1.7.10.4
#1 lore raw

Am 31.07.2013 07:00, schrieb Stefan Weil:

Quoted 10 lines

Shifting a long int (32 bit) by 40 bit positions won't work. Compiler message:

hw/core/qdev-properties.c: In function ‘print_size’:
hw/core/qdev-properties.c:1180:5: warning: left shift count >= width of type

---
 hw/core/qdev-properties.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Compare rth's patch:
http://patchwork.ozlabs.org/patch/263513/

Andreas

Quoted 15 lines
hw/core/qdev-properties.c +1 -1
index 8d43a8d..e82ab87 100644
@@ -1177,7 +1177,7 @@ static int print_size(DeviceState *dev, Property *prop, char *dest, size_t len)
     int i = 0;
     uint64_t div;
 
-    for (div = (long int)1 << 40; !(*ptr / div) ; div >>= 10) {
+    for (div = 1ULL << 40; !(*ptr / div); div >>= 10) {
         i++;
     }
     return snprintf(dest, len, "%0.03f%c", (double)*ptr/div, suffixes[i]);
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg