From 3b2ad1bc370653e90d6b2fa9cfc587a7aea405f3 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 21 Oct 2007 15:32:33 -0700 Subject: [PATCH] float.c: correct exponent capping MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Actually enforce the exponent capping, as opposed to only enforcing it to within a factor of 10. Furthermore, continue to scan the string in order to check for invalid characters. Finally, 16384 is too tight of a bound for a binary exponent: it's a tight bound, but the shift added due to the digit string can move the cap into the active region (±16383). Thus, change it to 20000 to be on the safe side. --- float.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/float.c b/float.c index db641800..843dbdfa 100644 --- a/float.c +++ b/float.c @@ -141,9 +141,8 @@ static int32_t read_exponent(const char *string, int32_t max) * in single, double, and extended precision, but * sufficient to avoid signed integer wraparound. */ - if (i > max) { - break; - } + if (i > max) + i = max; } else if (*string == '_') { /* do nothing */ } else { @@ -494,7 +493,7 @@ static bool ieee_flconvert_hex(const char *string, uint16_t * mant, } } else if (c == 'p' || c == 'P') { int32_t e; - e = read_exponent(string, 16384); + e = read_exponent(string, 20000); if (e == INT32_MAX) return false; twopwr += e; -- 2.11.4.GIT