summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-07-18 01:55:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-07-18 01:55:15 +0000
commit4a1513e2fb71b3fe8a67fdde3189e3857daa855d (patch)
tree43a2d5a409497b86c50dbc005eddd5d810bd61b6 /object.c
parent575f1320d419d53c43eb4e0b7e52cfb674fcdadb (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/trunk@10553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/object.c b/object.c
index 733f4f88f9..9ede440c53 100644
--- a/object.c
+++ b/object.c
@@ -2063,13 +2063,17 @@ rb_cstr_to_dbl(const char *p, int 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;
while (ISSPACE(*p)) p++;
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) {
@@ -2100,18 +2104,20 @@ rb_cstr_to_dbl(const char *p, int 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;
}