summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2015-12-14 10:39:39 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2015-12-14 10:59:56 +0900
commit19c744e14d63996dd5e64db3f8a4440099079ac3 (patch)
tree45282a2f2c0e34d960fe4684823b6fdc94cc2738 /src/string.c
parent4a6a11486cac49fa872a8323342b1dfb85743941 (diff)
downloadmruby-19c744e14d63996dd5e64db3f8a4440099079ac3.tar.gz
mruby-19c744e14d63996dd5e64db3f8a4440099079ac3.zip
mrb_str_len_to_inum(): fixed a bug with separating _ in the digits; ref #3043
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/string.c b/src/string.c
index 79606f1af..552293a46 100644
--- a/src/string.c
+++ b/src/string.c
@@ -2125,15 +2125,21 @@ mrb_str_len_to_inum(mrb_state *mrb, const char *str, size_t len, int base, int b
break;
} /* end of switch (base) { */
if (*p == '0') { /* squeeze preceding 0s */
- while (p<pend && ((c = *++p) == '0' || c == '_')) {
+ p++;
+ while (p<pend) {
+ c = *p++;
if (c == '_') {
- if (*p == '_') {
+ if (p<pend && *p == '_') {
if (badcheck) goto bad;
break;
}
+ continue;
+ }
+ if (c != '0') {
+ p--;
+ break;
}
}
- if (!(c = *p) || ISSPACE(c)) --p;
}
c = *p;
if (badcheck && c == '\0') {