summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2016-11-25 09:27:32 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2016-11-25 09:27:32 +0900
commit7f05ba86f2dee182bde6d6f2f1840f1edd030a37 (patch)
tree0ed6f168be786b68bb0b7713c706ca8be50d742c
parent9f7701e27a136b033cdc1b3fd05ee9898e1ea802 (diff)
parent30f12ba4bcfaf7dd4d0a02cb64c664fea804cf7d (diff)
downloadmruby-7f05ba86f2dee182bde6d6f2f1840f1edd030a37.tar.gz
mruby-7f05ba86f2dee182bde6d6f2f1840f1edd030a37.zip
Merge branch 'bouk-127-segfaults'
-rw-r--r--mrbgems/mruby-compiler/core/codegen.c8
-rw-r--r--test/t/codegen.rb15
2 files changed, 20 insertions, 3 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index 8de15aee3..25db887a0 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -772,6 +772,8 @@ attrsym(codegen_scope *s, mrb_sym a)
return mrb_intern(s->mrb, name2, len+1);
}
+#define CALL_MAXARGS 127
+
static int
gen_values(codegen_scope *s, node *t, int val)
{
@@ -780,7 +782,9 @@ gen_values(codegen_scope *s, node *t, int val)
while (t) {
is_splat = (intptr_t)t->car->car == NODE_SPLAT; /* splat mode */
- if (n >= 127 || is_splat) {
+ if (
+ n >= CALL_MAXARGS - 1 /* need to subtract one because vm.c expects an array if n == CALL_MAXARGS */
+ || is_splat) {
if (val) {
if (is_splat && n == 0 && (intptr_t)t->car->cdr->car == NODE_ARRAY) {
codegen(s, t->car->cdr, VAL);
@@ -831,8 +835,6 @@ gen_values(codegen_scope *s, node *t, int val)
return n;
}
-#define CALL_MAXARGS 127
-
static void
gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
{
diff --git a/test/t/codegen.rb b/test/t/codegen.rb
index 7177053ae..7d6efdc98 100644
--- a/test/t/codegen.rb
+++ b/test/t/codegen.rb
@@ -31,3 +31,18 @@ assert('codegen absorbs arguments to redo and retry if they are the argument of
end
end
end
+
+assert('method call with exactly 127 arguments') do
+ def args_to_ary(*args)
+ args
+ end
+
+ assert_equal [0]*127, args_to_ary(
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+ )
+end