summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-23 17:40:05 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-23 17:40:05 +0000
commitf9593a4fc4a68f0a48d6182c5183b701eb583776 (patch)
tree0d3e4b9bfed72460c6e9443d2c56859b56c7ffb7 /hash.c
parentebe322b1712b4b49528eb056c08dfb99af233e7c (diff)
merge revision(s) 21423:
* 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_8_7@22580 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 3f269becb5..771eab1069 100644
--- a/hash.c
+++ b/hash.c
@@ -357,10 +357,16 @@ rb_hash_s_create(argc, argv, 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;
}