]> git.proxmox.com Git - qemu.git/commitdiff
Fix overflow when multiplying two large positive numbers.
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>
Tue, 23 Oct 2007 23:22:54 +0000 (23:22 +0000)
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>
Tue, 23 Oct 2007 23:22:54 +0000 (23:22 +0000)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3429 c046a42c-6fe2-441c-8c8c-71466251a162

host-utils.c

index 10341063f12a75859c2a949e70319ea31163ee8f..cf2c6f8f1aee321c06fab483a65fcf147b4223fd 100644 (file)
@@ -43,7 +43,8 @@ void muls64(int64_t *phigh, int64_t *plow, int64_t a, int64_t b)
     ph = (a >> 32) * (b >> 32);
 
     ph += (int64_t)pm1 >> 32;
-    pm1 = (uint64_t)((uint32_t)pm1) + pm2 + (pl >> 32);
+    ph += (int64_t)pm2 >> 32;
+    pm1 = (uint64_t)((uint32_t)pm1) + (uint64_t)((uint32_t)pm2) + (pl >> 32);
 
     *phigh = ph + ((int64_t)pm1 >> 32);
     *plow = (pm1 << 32) + (uint32_t)pl;
@@ -67,7 +68,8 @@ void mulu64(uint64_t *phigh, uint64_t *plow, uint64_t a, uint64_t b)
     ph = (a >> 32) * (b >> 32);
 
     ph += pm1 >> 32;
-    pm1 = (uint64_t)((uint32_t)pm1) + pm2 + (pl >> 32);
+    ph += pm2 >> 32;
+    pm1 = (uint64_t)((uint32_t)pm1) + (uint64_t)((uint32_t)pm2) + (pl >> 32);
 
     *phigh = ph + (pm1 >> 32);
     *plow = (pm1 << 32) + (uint32_t)pl;