From 28a0d04ee6650069e7912ea69d37376323dab17b Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Thu, 28 Sep 2006 00:48:06 +0000 Subject: [PATCH] Fix mulIntMayOflo on 64-bit arches; fixes trac #867 We were assuming we could multiply 2 32-bit numbers without overflowing a 64-bit number, but we can't as the top bit is the sign bit. --- includes/Stg.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/Stg.h b/includes/Stg.h index 8e3da0f..5cd3701 100644 --- a/includes/Stg.h +++ b/includes/Stg.h @@ -442,7 +442,9 @@ typedef union { /* Approximate version when we don't have long arithmetic (on 64-bit archs) */ -#define HALF_POS_INT (((I_)1) << (BITS_IN (I_) / 2)) +/* If we have n-bit words then we have n-1 bits after accounting for the + * sign bit, so we can fit the result of multiplying 2 (n-1)/2-bit numbers */ +#define HALF_POS_INT (((I_)1) << ((BITS_IN (I_) - 1) / 2)) #define HALF_NEG_INT (-HALF_POS_INT) #define mulIntMayOflo(a,b) \ -- 1.7.10.4