Leave hash->ht to be NULL if initial capacity is zero.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2017-11-19 03:46:58 +09:00
parent 7405821f5a
commit 9b2454c94d
+4 -1
View File
@@ -144,7 +144,10 @@ mrb_hash_new_capa(mrb_state *mrb, mrb_int capa)
h = (struct RHash*)mrb_obj_alloc(mrb, MRB_TT_HASH, mrb->hash_class);
/* khash needs 1/4 empty space so it is not resized immediately */
h->ht = kh_init_size(ht, mrb, (khint_t)(capa*4/3));
if (capa == 0)
h->ht = 0;
else
h->ht = kh_init_size(ht, mrb, (khint_t)(capa*4/3));
h->iv = 0;
return mrb_obj_value(h);
}