From 2f93e39970c32520f347f65d5cd7fd4453f429ab Mon Sep 17 00:00:00 2001 From: matz Date: Sat, 24 Oct 2009 16:53:11 +0000 Subject: * hash.c (rb_hash_set_default_proc): checks arity of defalt_proc of a Hash. [ruby-core:26087] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'hash.c') diff --git a/hash.c b/hash.c index 3fab523ae..6c8fa5e0c 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; -- cgit