aboutsummaryrefslogtreecommitdiff
path: root/host-utils.c
diff options
context:
space:
mode:
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-10-23 23:22:54 +0000
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-10-23 23:22:54 +0000
commit67fc07d3fba681f3362f7644a69b7a581a2670e8 (patch)
tree03dbb59e9c6c9136dcafe13004e5be56c20badc8 /host-utils.c
parent9278480e8f9155fc3b3ce459efd12b500a611b7f (diff)
downloadqemu-67fc07d3fba681f3362f7644a69b7a581a2670e8.zip
qemu-67fc07d3fba681f3362f7644a69b7a581a2670e8.tar.gz
qemu-67fc07d3fba681f3362f7644a69b7a581a2670e8.tar.bz2
Fix overflow when multiplying two large positive numbers.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3429 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'host-utils.c')
-rw-r--r--host-utils.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/host-utils.c b/host-utils.c
index 1034106..cf2c6f8 100644
--- a/host-utils.c
+++ b/host-utils.c
@@ -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;