diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | hash.c | 12 |
2 files changed, 14 insertions, 3 deletions
@@ -1,3 +1,8 @@ +Sun Jan 11 09:47:30 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * hash.c (rb_hash_s_create): set nil as the value if assoc length + is not enough. [ruby-core:21249] + Sat Jan 10 21:17:28 2009 Tanaka Akira <akr@fsij.org> * ext/socket/mkconstants.rb: don't generate unintended newlines. @@ -348,10 +348,16 @@ rb_hash_s_create(int argc, VALUE *argv, VALUE klass) hash = hash_alloc(klass); for (i = 0; i < RARRAY_LEN(tmp); ++i) { VALUE v = rb_check_array_type(RARRAY_PTR(tmp)[i]); - + VALUE key, val = Qnil; + if (NIL_P(v)) continue; - if (RARRAY_LEN(v) < 1 || 2 < RARRAY_LEN(v)) continue; - rb_hash_aset(hash, RARRAY_PTR(v)[0], RARRAY_PTR(v)[1]); + switch (RARRAY_LEN(v)) { + case 2: + val = RARRAY_PTR(v)[1]; + case 1: + key = RARRAY_PTR(v)[0]; + rb_hash_aset(hash, key, val); + } } return hash; } |