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 | 95f289afb1929b131213e250cdc9bc0f5177a601 (patch) | |
tree | 266ad745ab2965dc1a8553c144842910a3b37e5d | |
parent | 9feb788b7f30fbe9e4654be22daede9924f20603 (diff) | |
download | txr-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.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; } } |