summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-12-10 11:09:55 +0900
committerGitHub <[email protected]>2019-12-10 11:09:55 +0900
commit543a9f84d11c2c0e96de52bd2e936467f13d26e8 (patch)
treecbd6300e6f457c450d76f225a76a2ca741b783f4 /src
parent694089fafe4eae36c379a3d918d540eb0c4b8661 (diff)
parent0893ee492c189e4d2c5badfd326a2e45049c89a5 (diff)
downloadmruby-543a9f84d11c2c0e96de52bd2e936467f13d26e8.tar.gz
mruby-543a9f84d11c2c0e96de52bd2e936467f13d26e8.zip
Merge pull request #4858 from shuujii/fix-that-String-to_f-accepts-consecutive-_-as-a-numeric-expression
Fix that `String#to_f` accepts consecutive `_` as a numeric expression
Diffstat (limited to 'src')
-rw-r--r--src/string.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/string.c b/src/string.c
index 61fbd4ded..f75679513 100644
--- a/src/string.c
+++ b/src/string.c
@@ -2522,15 +2522,10 @@ bad:
while (p < end && n < e) prev = *n++ = *p++;
while (*p) {
if (*p == '_') {
- /* remove underscores between digits */
- if (badcheck) {
- if (n == buf || !ISDIGIT(prev)) goto bad;
- ++p;
- if (!ISDIGIT(*p)) goto bad;
- }
- else {
- while (*++p == '_');
- continue;
+ /* remove an underscore between digits */
+ if (n == buf || !ISDIGIT(prev) || (++p, !ISDIGIT(*p))) {
+ if (badcheck) goto bad;
+ break;
}
}
prev = *p++;