aboutsummaryrefslogtreecommitdiffstats
path: root/compile.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-13 09:04:32 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-13 09:04:32 +0000
commit73dd7cb8273dda646ea5029c0529c2e187df2444 (patch)
tree8fc7b7396059745163a8d4c224c82647da9345e5 /compile.c
parent9b50a1dc54bf232be9d7a16642cf1625d731e10a (diff)
downloadruby-73dd7cb8273dda646ea5029c0529c2e187df2444.tar.gz
range.c: prohibit `(1..nil)`
Now endless range can be created by either a literal `(1..)` or explicit range creation `Range.new(1, nil)`. [Bug #14845] This change is intended for "early failure"; for example, `(1..var).to_a` causes out of memory if `var` is inadvertently nil. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/compile.c b/compile.c
index 21971830ea..2caf92ecf1 100644
--- a/compile.c
+++ b/compile.c
@@ -7188,10 +7188,10 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
case NODE_DOT2:
case NODE_DOT3:{
int excl = type == NODE_DOT3;
- VALUE flag = INT2FIX(excl);
const NODE *b = node->nd_beg;
const NODE *e = node->nd_end;
- if (number_literal_p(b) && number_literal_p(e)) {
+ VALUE flag = INT2FIX(excl | (e ? 0 : 2));
+ if (number_literal_p(b) && e && number_literal_p(e)) {
if (!popped) {
VALUE val = rb_range_new(b->nd_lit, e->nd_lit, excl);
iseq_add_mark_object_compile_time(iseq, val);