diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-03-01 15:08:13 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-03-01 15:08:13 +0000 |
commit | b4b3180bfab8c1027a3a082013f5ebd9c8fb6775 (patch) | |
tree | 41449f9c4218ea98cf4a472aa6076988ec229f07 /object.c | |
parent | 8ba29591afdd045a8824bddce88aa872630b4ebb (diff) | |
download | bundler-b4b3180bfab8c1027a3a082013f5ebd9c8fb6775.tar.gz |
* object.c (rb_cstr_to_dbl): check for successive underscores.
[ruby-dev:33952]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r-- | object.c | 23 |
1 files changed, 14 insertions, 9 deletions
@@ -2042,7 +2042,7 @@ rb_cstr_to_dbl(const char *p, int badcheck) if (!p) return 0.0; q = p; - while (ISSPACE(*p)) p++; + while (ISSPACE(*p)) p++; d = strtod(p, &end); if (errno == ERANGE) { OutOfRange(); @@ -2050,8 +2050,8 @@ rb_cstr_to_dbl(const char *p, int badcheck) errno = 0; } if (p == end) { - bad: if (badcheck) { + bad: rb_invalid_str(q, "Float()"); } return d; @@ -2060,19 +2060,24 @@ rb_cstr_to_dbl(const char *p, int badcheck) char buf[DBL_DIG * 4 + 10]; char *n = buf; char *e = buf + sizeof(buf) - 1; + char prev = 0; while (p < end && n < e) *n++ = *p++; - while (n < e && *p) { + while (*p) { if (*p == '_') { /* remove underscores between digits */ - if (n == buf || !ISDIGIT(n[-1])) goto bad; - while (*++p == '_'); - if (!ISDIGIT(*p)) { - if (badcheck) goto bad; - break; + if (badcheck) { + if (n == buf || !ISDIGIT(prev)) goto bad; + ++p; + if (!ISDIGIT(*p)) goto bad; + } + else { + while (*++p == '_'); + continue; } } - *n++ = *p++; + prev = *p++; + if (n < e) *n++ = prev; } *n = '\0'; p = buf; |