summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-11-15 06:25:49 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-11-15 06:25:49 -0800
commit1218e286e5838e225a26875cb934bcbae48b3e17 (patch)
tree03c56c1932fb71fb6206df55a299b3d50c07f356
parenta68badce7390a6e98e69ab17240265215ce764d4 (diff)
downloadtxr-1218e286e5838e225a26875cb934bcbae48b3e17.tar.gz
txr-1218e286e5838e225a26875cb934bcbae48b3e17.tar.bz2
txr-1218e286e5838e225a26875cb934bcbae48b3e17.zip
mpi: must clamp result of conversion to bignum.
* mpi/mpi.c (mp_set_uintptr, mp_set_double_intptr): The value of z might not require all of the digits implied by the size of its C data type. We must clamp the result to trim trailing zero limbs from the bignum.
-rw-r--r--mpi/mpi.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/mpi/mpi.c b/mpi/mpi.c
index 2777fa21..2a2fea0d 100644
--- a/mpi/mpi.c
+++ b/mpi/mpi.c
@@ -566,6 +566,7 @@ mp_err mp_set_uintptr(mp_int *mp, uint_ptr_t z)
DIGIT(mp, ix) = (z >> shift) & MP_DIGIT_MAX;
}
+ s_mp_clamp(mp);
} else {
mp_set(mp, z);
}
@@ -635,6 +636,8 @@ mp_err mp_set_double_intptr(mp_int *mp, double_intptr_t z)
DIGIT(mp, ix) = (v >> shift) & MP_DIGIT_MAX;
}
+ s_mp_clamp(mp);
+
if(z < 0)
SIGN(mp) = MP_NEG;