summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2015-12-16 14:47:49 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2015-12-16 14:49:08 +0900
commitd18c55fca75c0f824cc3d85f5bb795efd41319f8 (patch)
treedef1de1e3faa6aa2b47463b17bd7d7c80c14ce40 /src/string.c
parent80c1c60762495f128fea2a570a91172af585474d (diff)
downloadmruby-d18c55fca75c0f824cc3d85f5bb795efd41319f8.tar.gz
mruby-d18c55fca75c0f824cc3d85f5bb795efd41319f8.zip
mrb_str_len_to_inum(): fixed a bug with underscores in digits; fix #3049
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/string.c b/src/string.c
index eda4c3fb8..3fbea4c99 100644
--- a/src/string.c
+++ b/src/string.c
@@ -2145,29 +2145,24 @@ mrb_str_len_to_inum(mrb_state *mrb, const char *str, size_t len, int base, int b
}
}
}
- c = *p;
- if (badcheck && c == '\0') {
- goto bad;
- }
- c = conv_digit(c);
- if (c < 0 || c >= base) {
+ if (p == pend) {
if (badcheck) goto bad;
return mrb_fixnum_value(0);
}
-
for ( ;p<pend;p++) {
if (*p == '_') {
- if (p+1<pend && p[1] == '_') {
+ p++;
+ if (p==pend) {
if (badcheck) goto bad;
continue;
}
- p++;
- if (badcheck && p<pend)
- goto bad;
+ if (*p == '_') {
+ if (badcheck) goto bad;
+ break;
+ }
}
if (badcheck && *p == '\0') {
goto nullbyte;
- break;
}
c = conv_digit(*p);
if (c < 0 || c >= base) {