diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-07-18 01:55:15 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-07-18 01:55:15 +0000 |
commit | 7b0c9cf2e2a5e8a084d122e3432457c324a7bd89 (patch) | |
tree | 48d8436380c4f99d5301e0104745e411ae4c25b9 /object.c | |
parent | 1c08471a41c9569f7370a08cc6ce7de9f3510dd0 (diff) |
* 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
Diffstat (limited to 'object.c')
-rw-r--r-- | object.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -2213,6 +2213,9 @@ rb_cstr_to_dbl(p, badcheck) const char *q; char *end; double d; + const char *ellipsis = ""; + int w; +#define OutOfRange() (((w = end - p) > 20) ? (w = 20, ellipsis = "...") : (ellipsis = "")) if (!p) return 0.0; q = p; @@ -2224,7 +2227,8 @@ rb_cstr_to_dbl(p, badcheck) } d = strtod(p, &end); 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; } if (p == end) { @@ -2258,18 +2262,20 @@ rb_cstr_to_dbl(p, badcheck) p = buf; d = strtod(p, &end); 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; } if (badcheck) { - if (p == end) goto bad; + if (!end || p == end) goto bad; while (*end && ISSPACE(*end)) end++; if (*end) goto bad; } } if (errno == ERANGE) { 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; } |