summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-07-23 07:06:35 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2020-07-23 07:06:35 +0900
commite7599050dc7055bc013b4114401e62670bf86828 (patch)
tree32da9ebd5baafce9d434798394e0b83ba2f04bd2 /src
parent0e9bd248271b9f3d8de42e0fbc932c3148d91787 (diff)
downloadmruby-e7599050dc7055bc013b4114401e62670bf86828.tar.gz
mruby-e7599050dc7055bc013b4114401e62670bf86828.zip
Fix a bug with `ht_index` called with `size==0`; fix #5046
It happens when a hash made empty calls `rehash`.
Diffstat (limited to 'src')
-rw-r--r--src/hash.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/hash.c b/src/hash.c
index 79b61d8b2..9a690bf1a 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -174,6 +174,11 @@ ht_index(mrb_state *mrb, htable *t)
segment *seg;
size_t i;
+ if (size == 0) {
+ t->index = NULL;
+ mrb_free(mrb, index);
+ return;
+ }
/* allocate index table */
if (index && index->size >= UPPER_BOUND(index->capa)) {
size = index->capa+1;
@@ -194,7 +199,7 @@ ht_index(mrb_state *mrb, htable *t)
index->table[i] = NULL;
}
- /* rebuld index */
+ /* rebuild index */
mask = HT_MASK(index);
seg = t->rootseg;
while (seg) {