summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-12 13:32:30 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-12 13:32:30 +0000
commit823491511ea24af1f04293ae06f331b393e26ef9 (patch)
tree85055bfa4ca6370a90ebc1235a3d281b6da1860b /hash.c
parent6889d3d361767a244fa1d3b3364274a1bf3965bc (diff)
merges r21424 from trunk into ruby_1_9_1.
* hash.c (rb_hash_s_create): set nil as the value if assoc length is not enough. [ruby-core:21249] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@21459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/hash.c b/hash.c
index a058a00a91..4c78122a02 100644
--- a/hash.c
+++ b/hash.c
@@ -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;
}