Skip to content

Commit 7b0c9cf

Browse files
committed
* 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/branches/ruby_1_8@10553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 1c08471 commit 7b0c9cf

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Tue Jul 18 10:53:37 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* object.c (rb_cstr_to_dbl): limit out-of-range message.
4+
5+
* util.c (ruby_strtod): return end pointer even if ERANGE occurred.
6+
fixed: [ruby-dev:29041]
7+
18
Mon Jul 18 00:43:05 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
29

310
* util.c (ruby_strtod): stop at dot not followed by digits.

object.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,9 @@ rb_cstr_to_dbl(p, badcheck)
22132213
const char *q;
22142214
char *end;
22152215
double d;
2216+
const char *ellipsis = "";
2217+
int w;
2218+
#define OutOfRange() (((w = end - p) > 20) ? (w = 20, ellipsis = "...") : (ellipsis = ""))
22162219

22172220
if (!p) return 0.0;
22182221
q = p;
@@ -2224,7 +2227,8 @@ rb_cstr_to_dbl(p, badcheck)
22242227
}
22252228
d = strtod(p, &end);
22262229
if (errno == ERANGE) {
2227-
rb_warn("Float %*s out of range", end-p, p);
2230+
OutOfRange();
2231+
rb_warn("Float %.*s%s out of range", w, p, ellipsis);
22282232
errno = 0;
22292233
}
22302234
if (p == end) {
@@ -2258,18 +2262,20 @@ rb_cstr_to_dbl(p, badcheck)
22582262
p = buf;
22592263
d = strtod(p, &end);
22602264
if (errno == ERANGE) {
2261-
rb_warn("Float %*s out of range", end-p, p);
2265+
OutOfRange();
2266+
rb_warn("Float %.*s%s out of range", w, p, ellipsis);
22622267
errno = 0;
22632268
}
22642269
if (badcheck) {
2265-
if (p == end) goto bad;
2270+
if (!end || p == end) goto bad;
22662271
while (*end && ISSPACE(*end)) end++;
22672272
if (*end) goto bad;
22682273
}
22692274
}
22702275
if (errno == ERANGE) {
22712276
errno = 0;
2272-
rb_raise(rb_eArgError, "Float %s out of range", q);
2277+
OutOfRange();
2278+
rb_raise(rb_eArgError, "Float %.*s%s out of range", w, q, ellipsis);
22732279
}
22742280
return d;
22752281
}

util.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,11 +890,13 @@ ruby_strtod(string, endPtr)
890890

891891
if (exp >= MDMAXEXPT) {
892892
errno = ERANGE;
893-
return HUGE_VAL * (sign ? -1.0 : 1.0);
893+
fraction = HUGE_VAL;
894+
goto ret;
894895
}
895896
else if (exp < MDMINEXPT) {
896897
errno = ERANGE;
897-
return 0.0 * (sign ? -1.0 : 1.0);
898+
fraction = 0.0;
899+
goto ret;
898900
}
899901
fracExp = exp;
900902
exp += 9;
@@ -940,6 +942,7 @@ ruby_strtod(string, endPtr)
940942
fraction = frac1 + frac2;
941943
}
942944

945+
ret:
943946
if (endPtr != NULL) {
944947
*endPtr = (char *)p;
945948
}

0 commit comments

Comments
 (0)