summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-05-21 07:36:35 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-05-21 07:36:35 -0700
commit95f289afb1929b131213e250cdc9bc0f5177a601 (patch)
tree266ad745ab2965dc1a8553c144842910a3b37e5d
parent9feb788b7f30fbe9e4654be22daede9924f20603 (diff)
downloadtxr-95f289afb1929b131213e250cdc9bc0f5177a601.tar.gz
txr-95f289afb1929b131213e250cdc9bc0f5177a601.tar.bz2
txr-95f289afb1929b131213e250cdc9bc0f5177a601.zip
mpi: bug converting most negative 64 bit value.
* mpi/mpi.c (s_mp_in_big_range): If the value is negative, extend the range. This is exactly the same fix as what was applied to mp_in_range in 2019 in commit 11b5c567124a61d8e8249a0fbcce47f2688573c6. This function should have been fixed at the same time. The corresponding test cases now pass.
-rw-r--r--mpi/mpi.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/mpi/mpi.c b/mpi/mpi.c
index dfe4e138..b1eb7e49 100644
--- a/mpi/mpi.c
+++ b/mpi/mpi.c
@@ -571,8 +571,9 @@ static int s_mp_in_big_range(mp_int *mp, double_uintptr_t lim, int unsig)
{
const unsigned ptrnd = (SIZEOF_DOUBLE_INTPTR + MP_DIGIT_SIZE - 1) / MP_DIGIT_SIZE;
mp_size nd = USED(mp);
+ int neg = ISNEG(mp);
- if (unsig && ISNEG(mp))
+ if (unsig && neg)
return 0;
if (nd < ptrnd)
@@ -584,7 +585,7 @@ static int s_mp_in_big_range(mp_int *mp, double_uintptr_t lim, int unsig)
{
mp_digit top = DIGITS(mp)[ptrnd - 1];
lim >>= ((ptrnd - 1) * MP_DIGIT_BIT);
- return top <= lim;
+ return (top - neg) <= lim;
}
}