From 399b0f280662fdb1621f03f2df408962f5c10409 Mon Sep 17 00:00:00 2001 From: corinna Date: Mon, 16 May 2011 13:34:04 +0000 Subject: [PATCH] * libc/stdlib/strtod.c (_strtod_r): Fix nf/nd counts to not exceed DBL_DIG. --- newlib/ChangeLog | 5 +++++ newlib/libc/stdlib/strtod.c | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 90dc61d994..4f4de06055 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,8 @@ +2011-05-16 Christian Bruel + + * libc/stdlib/strtod.c (_strtod_r): Fix nf/nd counts to not exceed + DBL_DIG. + 2011-05-15 Corinna Vinschen * libc/include/sys/features.h (_POSIX_THREAD_ATTR_STACKADDR): Define diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c index fe6aac2061..7e73b12ac9 100644 --- a/newlib/libc/stdlib/strtod.c +++ b/newlib/libc/stdlib/strtod.c @@ -309,8 +309,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), } nd0 = nd; if (strncmp (s, _localeconv_r (ptr)->decimal_point, - strlen (_localeconv_r (ptr)->decimal_point)) == 0) - { + strlen (_localeconv_r (ptr)->decimal_point)) == 0) { decpt = 1; c = *(s += strlen (_localeconv_r (ptr)->decimal_point)); if (!nd) { @@ -328,25 +327,28 @@ _DEFUN (_strtod_r, (ptr, s00, se), have_dig: nz++; if (c -= '0') { - nf += nz; for(i = 1; i < nz; i++) { - if (nd++ <= DBL_DIG + 1) { - if (nd < 10) + if (nd <= DBL_DIG + 1) { + if (nd + i < 10) y *= 10; else z *= 10; } } - if (nd++ <= DBL_DIG + 1) { - if (nd < 10) + if (nd <= DBL_DIG + 1) { + if (nd + i < 10) y = 10*y + c; else z = 10*z + c; } - nz = 0; + if (nd <= DBL_DIG + 1) { + nf += nz; + nd += nz; } + nz = 0; } } + } dig_done: e = 0; if (c == 'e' || c == 'E') { -- 2.11.0