* object.c (rb_cstr_to_dbl): limit out-of-range message.

* util.c (ruby_strtod): return end pointer even if ERANGE occurred.
  fixed: [ruby-dev:29041]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2006-07-18 01:55:15 +00:00
parent 575f1320d4
commit 4a1513e2fb
3 changed files with 22 additions and 6 deletions

View File

@ -1,3 +1,10 @@
Tue Jul 18 10:53:37 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* object.c (rb_cstr_to_dbl): limit out-of-range message.
* util.c (ruby_strtod): return end pointer even if ERANGE occurred.
fixed: [ruby-dev:29041]
Mon Jul 18 00:43:05 2006 Nobuyoshi Nakada <nobu@ruby-lang.org> Mon Jul 18 00:43:05 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* util.c (ruby_strtod): stop at dot not followed by digits. * util.c (ruby_strtod): stop at dot not followed by digits.

View File

@ -2063,13 +2063,17 @@ rb_cstr_to_dbl(const char *p, int badcheck)
const char *q; const char *q;
char *end; char *end;
double d; double d;
const char *ellipsis = "";
int w;
#define OutOfRange() (((w = end - p) > 20) ? (w = 20, ellipsis = "...") : (ellipsis = ""))
if (!p) return 0.0; if (!p) return 0.0;
q = p; q = p;
while (ISSPACE(*p)) p++; while (ISSPACE(*p)) p++;
d = strtod(p, &end); d = strtod(p, &end);
if (errno == ERANGE) { if (errno == ERANGE) {
rb_warn("Float %*s out of range", end-p, p); OutOfRange();
rb_warn("Float %.*s%s out of range", w, p, ellipsis);
errno = 0; errno = 0;
} }
if (p == end) { if (p == end) {
@ -2100,18 +2104,20 @@ rb_cstr_to_dbl(const char *p, int badcheck)
p = buf; p = buf;
d = strtod(p, &end); d = strtod(p, &end);
if (errno == ERANGE) { if (errno == ERANGE) {
rb_warn("Float %*s out of range", end-p, p); OutOfRange();
rb_warn("Float %.*s%s out of range", w, p, ellipsis);
errno = 0; errno = 0;
} }
if (badcheck) { if (badcheck) {
if (p == end) goto bad; if (!end || p == end) goto bad;
while (*end && ISSPACE(*end)) end++; while (*end && ISSPACE(*end)) end++;
if (*end) goto bad; if (*end) goto bad;
} }
} }
if (errno == ERANGE) { if (errno == ERANGE) {
errno = 0; errno = 0;
rb_raise(rb_eArgError, "Float %s out of range", q); OutOfRange();
rb_raise(rb_eArgError, "Float %.*s%s out of range", w, q, ellipsis);
} }
return d; return d;
} }

7
util.c
View File

@ -874,11 +874,13 @@ ruby_strtod(
if (exp >= MDMAXEXPT) { if (exp >= MDMAXEXPT) {
errno = ERANGE; errno = ERANGE;
return HUGE_VAL * (sign ? -1.0 : 1.0); fraction = HUGE_VAL;
goto ret;
} }
else if (exp < MDMINEXPT) { else if (exp < MDMINEXPT) {
errno = ERANGE; errno = ERANGE;
return 0.0 * (sign ? -1.0 : 1.0); fraction = 0.0;
goto ret;
} }
fracExp = exp; fracExp = exp;
exp += 9; exp += 9;
@ -924,6 +926,7 @@ ruby_strtod(
fraction = frac1 + frac2; fraction = frac1 + frac2;
} }
ret:
if (endPtr != NULL) { if (endPtr != NULL) {
*endPtr = (char *)p; *endPtr = (char *)p;
} }