diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-05-21 07:36:35 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-05-21 07:36:35 -0700 |
commit | 25d7225b49b7f0228c9f1b97102aaea191e6a775 (patch) | |
tree | 266ad745ab2965dc1a8553c144842910a3b37e5d | |
parent | a63cdae8efd80d1130f54cac8a7d2767a0d87342 (diff) | |
download | txr-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.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -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; } } |