diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-11 00:47:32 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-11 00:47:32 +0000 |
commit | 5a38751d0286d0a69ff301491207d7fd61b12bd2 (patch) | |
tree | 93acf712b8ec4df461aad871c504f9c9c0f387a2 /hash.c | |
parent | b802f1bb02c5bad3e7721ae22981ed9074e1f2e6 (diff) | |
download | ruby-5a38751d0286d0a69ff301491207d7fd61b12bd2.tar.gz |
* 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/trunk@21424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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; } |