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
commit25d7225b49b7f0228c9f1b97102aaea191e6a775 (patch)
tree266ad745ab2965dc1a8553c144842910a3b37e5d
parenta63cdae8efd80d1130f54cac8a7d2767a0d87342 (diff)
downloadtxr-25d7225b49b7f0228c9f1b97102aaea191e6a775.tar.gz
txr-25d7225b49b7f0228c9f1b97102aaea191e6a775.tar.bz2
txr-25d7225b49b7f0228c9f1b97102aaea191e6a775.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 d40e471e4d1e4c4a721da3d8a95dca99cc51cff0. 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;
}
}