diff options
author | ache <ache@FreeBSD.org> | 2001-11-28 05:39:21 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2001-11-28 05:39:21 +0000 |
commit | 10211a493a50db7fa5a56f3d4c55fc3d6b14866a (patch) | |
tree | f13d263fda9583c888abb45ac6f2edb4f9b3f873 | |
parent | 0c87565de61d7b353d9bc41f92cc0a9a9a140af5 (diff) | |
download | FreeBSD-src-10211a493a50db7fa5a56f3d4c55fc3d6b14866a.zip FreeBSD-src-10211a493a50db7fa5a56f3d4c55fc3d6b14866a.tar.gz |
Use stricter tests to disallow national digits > 9
Optimize national digits code a bit
-rw-r--r-- | lib/libc/stdlib/strtod.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/libc/stdlib/strtod.c b/lib/libc/stdlib/strtod.c index 2f2e259..71fccac 100644 --- a/lib/libc/stdlib/strtod.c +++ b/lib/libc/stdlib/strtod.c @@ -1192,7 +1192,7 @@ strtod #endif { int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, - e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; + e, e1, esign, i, j, k, n, nd, nd0, nf, nz, nz0, sign; CONST char *s, *s0, *s1; double aadj, aadj1, adj, rv, rv0; long L; @@ -1227,18 +1227,18 @@ strtod } s0 = s; y = z = 0; - for (nd = nf = 0; isdigit(c = (unsigned char)*s); nd++, s++) + for (nd = nf = 0; isdigit(c = (unsigned char)*s) && (n = digitoint(c)) <= 9; nd++, s++) if (nd < 9) - y = 10*y + digittoint(c); + y = 10*y + n; else if (nd < 16) - z = 10*z + digittoint(c); + z = 10*z + n; nd0 = nd; if ((char)c == decimal_point) { c = (unsigned char)*++s; if (!nd) { for (; isdigit(c) && digittoint(c) == 0; c = (unsigned char)*++s) nz++; - if (isdigit(c)) { + if (isdigit(c) && (n = digittoint(c)) <= 9) { s0 = s; nf += nz; nz = 0; @@ -1246,10 +1246,10 @@ strtod } goto dig_done; } - for (; isdigit(c); c = (unsigned char)*++s) { + for (; isdigit(c) && (n = digittoint(c)) <= 9; c = (unsigned char)*++s) { have_dig: nz++; - if (digittoint(c) != 0) { + if (n > 0) { nf += nz; for (i = 1; i < nz; i++) if (nd++ < 9) @@ -1257,9 +1257,9 @@ strtod else if (nd <= DBL_DIG + 1) z *= 10; if (nd++ < 9) - y = 10*y + digittoint(c); + y = 10*y + n; else if (nd <= DBL_DIG + 1) - z = 10*z + digittoint(c); + z = 10*z + n; nz = 0; } } @@ -1279,14 +1279,14 @@ strtod case '+': c = (unsigned char)*++s; } - if (isdigit(c)) { + if (isdigit(c) && digittoint(c) <= 9) { while (isdigit(c) && digittoint(c) == 0) c = (unsigned char)*++s; - if (isdigit(c)) { - L = digittoint(c); + if (isdigit(c) && (n = digittoint(c)) <= 9) { + L = n; s1 = s; - while (isdigit(c = (unsigned char)*++s)) - L = 10*L + digittoint(c); + while (isdigit(c = (unsigned char)*++s) && (n = digittoint(c)) <= 9) + L = 10*L + n; if (s - s1 > 8 || L > 19999) /* Avoid confusion from exponents * so large that e might overflow. |