summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-24 16:53:11 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-24 16:53:11 +0000
commitba3bfda7a2c58a5eb9b6dacdd109a97492cc906f (patch)
treeaf63a4163e4f225e89c36207e89d5b61c8b6947d /hash.c
parent5f01ed26f2b9199ff9eb56ca3b00d850b27b79e7 (diff)
* hash.c (rb_hash_set_default_proc): checks arity of defalt_proc
of a Hash. [ruby-core:26087] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 3fab523ae5..6c8fa5e0c6 100644
--- a/hash.c
+++ b/hash.c
@@ -667,6 +667,7 @@ static VALUE
rb_hash_set_default_proc(VALUE hash, VALUE proc)
{
VALUE b;
+ int n;
rb_hash_modify(hash);
b = rb_check_convert_type(proc, T_DATA, "Proc", "to_proc");
@@ -676,6 +677,11 @@ rb_hash_set_default_proc(VALUE hash, VALUE proc)
rb_obj_classname(proc));
}
proc = b;
+ n = rb_proc_arity(proc);
+ if (rb_proc_lambda_p(proc) && n != 2 && (n >= 0 || n < -3)) {
+ if (n < 0) n = -n-1;
+ rb_raise(rb_eTypeError, "default_proc takes two arguments (2 for %d)", n);
+ }
RHASH(hash)->ifnone = proc;
FL_SET(hash, HASH_PROC_DEFAULT);
return proc;