Commit c85feaec authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #3337 from bouk/undef-127

Fix segfault when undef is called with more than 126 arguments
parents db6b6ff4 c8da3c4d
...@@ -2560,13 +2560,31 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -2560,13 +2560,31 @@ codegen(codegen_scope *s, node *tree, int val)
genop(s, MKOP_A(OP_TCLASS, cursp())); genop(s, MKOP_A(OP_TCLASS, cursp()));
push(); push();
while (t) { while (t) {
int symbol = new_msym(s, sym(t->car)); int symbol;
if (num >= CALL_MAXARGS - 1) {
pop_n(num);
genop(s, MKOP_ABC(OP_ARRAY, cursp(), cursp(), num));
while (t) {
symbol = new_msym(s, sym(t->car));
push();
genop(s, MKOP_ABx(OP_LOADSYM, cursp(), symbol));
pop();
genop(s, MKOP_AB(OP_ARYPUSH, cursp(), cursp()+1));
t = t->cdr;
}
num = CALL_MAXARGS;
break;
}
symbol = new_msym(s, sym(t->car));
genop(s, MKOP_ABx(OP_LOADSYM, cursp(), symbol)); genop(s, MKOP_ABx(OP_LOADSYM, cursp(), symbol));
push(); push();
t = t->cdr; t = t->cdr;
num++; num++;
} }
pop_n(num + 1); pop();
if (num < CALL_MAXARGS) {
pop_n(num);
}
genop(s, MKOP_ABC(OP_SEND, cursp(), undef, num)); genop(s, MKOP_ABC(OP_SEND, cursp(), undef, num));
if (val) { if (val) {
push(); push();
......
...@@ -63,3 +63,13 @@ assert('splat in case splat') do ...@@ -63,3 +63,13 @@ assert('splat in case splat') do
assert_equal [1], a assert_equal [1], a
end end
assert('undef with 127 or more arguments') do
assert_raise NameError do
undef
a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment