From 1e7aede9bd0fc454e56fb5cc74e34ea636f94cce Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 29 Aug 2005 13:14:22 +0000 Subject: [PATCH] Avoid shifting a 32-bit zero value by more than 31 bits. --- ChangeLog | 5 +++++ src/integer/bitwise/cl_I_ash_I.cc | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/ChangeLog b/ChangeLog index 238ca86..bde1149 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-08-27 Bruno Haible + + * src/integer/bitwise/cl_I_ash_I.cc (ash): Avoid shifting a 32-bit + zero value by more than 31 bits. + 2005-08-27 Bruno Haible Make the long-float overflow check work on 64-bit platforms. diff --git a/src/integer/bitwise/cl_I_ash_I.cc b/src/integer/bitwise/cl_I_ash_I.cc index 2ea5cd2..f4f6b9c 100644 --- a/src/integer/bitwise/cl_I_ash_I.cc +++ b/src/integer/bitwise/cl_I_ash_I.cc @@ -52,6 +52,7 @@ const cl_I ash (const cl_I& x, const cl_I& y) || len == ceiling(log2_intDsize+intCsize+1,intDsize)) if (mspref(arrayMSDptr(bn->data,len),0) >= (uintD)bit((log2_intDsize+intCsize)%intDsize)) cl_ash_error(y); + #if (log2_intDsize+intCsize > intDsize) #define IF_LENGTH(i) \ if (bn_minlength <= i && i <= ceiling(log2_intDsize+intCsize+1,intDsize) && (i == ceiling(log2_intDsize+intCsize+1,intDsize) || len == i)) IF_LENGTH(1) @@ -68,6 +69,11 @@ const cl_I ash (const cl_I& x, const cl_I& y) cl_abort(); #undef IF_LENGTH k = k << (intDsize-log2_intDsize); + #else + // log2_intDsize+intCsize <= intDsize, + // implies len==1 or len==2 && lspref(arrayLSDptr(bn->data,len),1) == 0. + k = 0; + #endif k |= lspref(arrayLSDptr(bn->data,len),0) >> log2_intDsize; i = lspref(arrayLSDptr(bn->data,len),0) % intDsize; #endif @@ -123,6 +129,7 @@ const cl_I ash (const cl_I& x, const cl_I& y) || len == ceiling(log2_intDsize+intCsize+1,intDsize)) if (mspref(arrayMSDptr(bn->data,len),0) < (uintD)(-bit((log2_intDsize+intCsize)%intDsize))) goto sign; + #if (log2_intDsize+intCsize > intDsize) #define IF_LENGTH(i) \ if (bn_minlength <= i && i <= ceiling(log2_intDsize+intCsize+1,intDsize) && (i == ceiling(log2_intDsize+intCsize+1,intDsize) || len == i)) IF_LENGTH(1) @@ -139,6 +146,11 @@ const cl_I ash (const cl_I& x, const cl_I& y) cl_abort(); #undef IF_LENGTH k = k << (intDsize-log2_intDsize); + #else + // log2_intDsize+intCsize <= intDsize, + // implies len==1 or len==2 && lspref(arrayLSDptr(bn->data,len),1) == ~0. + k = 0; + #endif k |= (uintD)(~lspref(arrayLSDptr(bn->data,len),0)) >> log2_intDsize; i = (uintD)(-lspref(arrayLSDptr(bn->data,len),0)) % intDsize; if (i == 0)