summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/array.c1
-rw-r--r--src/string.c20
2 files changed, 9 insertions, 12 deletions
diff --git a/src/array.c b/src/array.c
index 8190c2416..8547cfff4 100644
--- a/src/array.c
+++ b/src/array.c
@@ -1304,6 +1304,7 @@ init_ary_each(mrb_state *mrb, struct RClass *ary)
each_irep->nregs = 7;
each_irep->nlocals = 3;
p = mrb_proc_new(mrb, each_irep);
+ p->flags |= MRB_PROC_SCOPE | MRB_PROC_STRICT;
MRB_METHOD_FROM_PROC(m, p);
mrb_define_method_raw(mrb, ary, mrb_intern_lit(mrb, "each"), m);
}
diff --git a/src/string.c b/src/string.c
index 61fbd4ded..5a0a6a233 100644
--- a/src/string.c
+++ b/src/string.c
@@ -2354,7 +2354,7 @@ mrb_str_len_to_inum(mrb_state *mrb, const char *str, mrb_int len, mrb_int base,
if (*(p - 1) == '0')
p--;
}
- if (p == pend) {
+ if (p == pend || *p == '_') {
if (badcheck) goto bad;
return mrb_fixnum_value(0);
}
@@ -2393,9 +2393,10 @@ mrb_str_len_to_inum(mrb_state *mrb, const char *str, mrb_int len, mrb_int base,
}
val = (mrb_int)n;
if (badcheck) {
- if (p == str) goto bad; /* no number */
+ if (p == str) goto bad; /* no number */
+ if (*(p - 1) == '_') goto bad; /* trailing '_' */
while (p<pend && ISSPACE(*p)) p++;
- if (p<pend) goto bad; /* trailing garbage */
+ if (p<pend) goto bad; /* trailing garbage */
}
return mrb_fixnum_value(sign ? val : -val);
@@ -2522,15 +2523,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++;