From d7b7dfee537fbd0669933c20403c4c260130a218 Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Sat, 1 Dec 2018 08:33:02 +0100 Subject: [PATCH 1/2] explicit cast --- bn_mp_set_double.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bn_mp_set_double.c b/bn_mp_set_double.c index 0e230c7..f0de20c 100644 --- a/bn_mp_set_double.c +++ b/bn_mp_set_double.c @@ -24,7 +24,7 @@ int mp_set_double(mp_int *a, double b) } cast; cast.dbl = b; - exp = (unsigned)(cast.bits >> 52) & 0x7FFU; + exp = (int)((unsigned)(cast.bits >> 52) & 0x7FFU); frac = (cast.bits & ((1ULL << 52) - 1ULL)) | (1ULL << 52); if (exp == 0x7FF) { /* +-inf, NaN */ From 4d6a3cdc93024cf2e456a62c363342f15d7421f3 Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Sat, 1 Dec 2018 08:35:22 +0100 Subject: [PATCH 2/2] handle the last value of res --- bn_mp_set_double.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bn_mp_set_double.c b/bn_mp_set_double.c index f0de20c..6d84874 100644 --- a/bn_mp_set_double.c +++ b/bn_mp_set_double.c @@ -38,6 +38,10 @@ int mp_set_double(mp_int *a, double b) } res = (exp < 0) ? mp_div_2d(a, -exp, a, NULL) : mp_mul_2d(a, exp, a); + if (res != MP_OKAY) { + return res; + } + if (((cast.bits >> 63) != 0ULL) && (mp_iszero(a) == MP_NO)) { SIGN(a) = MP_NEG; }