From 18fbe4d0b74aa6e787b908a5509f834c7a1d6a18 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 23 Oct 2012 14:16:14 +0900 Subject: do not touch h from Hash when h might be NULL --- src/hash.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/hash.c') diff --git a/src/hash.c b/src/hash.c index 92dfff186..51f85f4e8 100644 --- a/src/hash.c +++ b/src/hash.c @@ -970,9 +970,10 @@ mrb_hash_keys(mrb_state *mrb, mrb_value hash) { khash_t(ht) *h = RHASH_TBL(hash); khiter_t k; - mrb_value ary = mrb_ary_new_capa(mrb, kh_size(h)); + mrb_value ary; - if (!h) return ary; + if (!h) return mrb_ary_new(mrb); + ary = mrb_ary_new_capa(mrb, kh_size(h)); for (k = kh_begin(h); k != kh_end(h); k++) { if (kh_exist(h, k)) { mrb_value v = kh_key(h,k); @@ -1000,9 +1001,10 @@ mrb_hash_values(mrb_state *mrb, mrb_value hash) { khash_t(ht) *h = RHASH_TBL(hash); khiter_t k; - mrb_value ary = mrb_ary_new_capa(mrb, kh_size(h)); + mrb_value ary; - if (!h) return ary; + if (!h) return mrb_ary_new(mrb); + ary = mrb_ary_new_capa(mrb, kh_size(h)); for (k = kh_begin(h); k != kh_end(h); k++) { if (kh_exist(h, k)){ mrb_value v = kh_value(h,k); -- cgit v1.2.3