summaryrefslogtreecommitdiffstats
path: root/mpi/mpi.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-04-28 06:58:53 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-04-28 06:58:53 -0700
commit49476d06993fd9df7d1e7ebe94ca508226ffa1f5 (patch)
tree441835fd5481398aea6707c189068c55dd359a1c /mpi/mpi.c
parent2523921a66ae7fbf9c03e69552141fbbead5b1df (diff)
downloadtxr-49476d06993fd9df7d1e7ebe94ca508226ffa1f5.tar.gz
txr-49476d06993fd9df7d1e7ebe94ca508226ffa1f5.tar.bz2
txr-49476d06993fd9df7d1e7ebe94ca508226ffa1f5.zip
Fix broken bignum to int_ptr_t conversion.
This one affects all platforms. The extra sign check and negation cancels out the one done in mp_get_uintptr, causing a positive value for a negative input value. * mpi/mpi.c (mp_get_intptr): Just coerce the uint_ptr_t result to int_ptr_t. That has the right semantics under that the bits are preserved (under two's complement, in every compiler I've ever used). The unsigned value from mp_get_uintptr already looks like the image of a two's complement value.
Diffstat (limited to 'mpi/mpi.c')
-rw-r--r--mpi/mpi.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/mpi/mpi.c b/mpi/mpi.c
index 96dc71d4..42a267b5 100644
--- a/mpi/mpi.c
+++ b/mpi/mpi.c
@@ -606,10 +606,9 @@ mp_err mp_get_uintptr(mp_int *mp, uint_ptr_t *z)
mp_err mp_get_intptr(mp_int *mp, int_ptr_t *z)
{
uint_ptr_t tmp = 0;
- int_ptr_t out;
mp_get_uintptr(mp, &tmp);
- out = tmp;
- *z = (SIGN(mp) == MP_NEG) ? -out : out;
+ /* Reliance on bitwise unsigned to two's complement conversion */
+ *z = (int_ptr_t) tmp;
return MP_OKAY;
}