From 424981309df3cefd2e2f99c5cb8975e4fca337aa Mon Sep 17 00:00:00 2001 From: John Sully Date: Sun, 2 Feb 2020 23:27:25 -0500 Subject: [PATCH] Handle case where src dict is larger in dictMerge Former-commit-id: c750fdb381f5dd3e92d251a82bd86533eb2cadf5 --- src/dict.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/dict.cpp b/src/dict.cpp index 740d743e8..33e73fc5d 100644 --- a/src/dict.cpp +++ b/src/dict.cpp @@ -179,6 +179,7 @@ int dictExpand(dict *d, unsigned long size) int dictMerge(dict *dst, dict *src) { + assert(dst != src); if (dictSize(src) == 0) return DICT_OK; @@ -188,12 +189,15 @@ int dictMerge(dict *dst, dict *src) return DICT_OK; } + if (dictSize(src) > dictSize(dst)) + std::swap(*dst, *src); + if (!dictIsRehashing(dst) && !dictIsRehashing(src)) { dst->ht[1] = dst->ht[0]; dst->ht[0] = src->ht[0]; - dst->rehashidx = 0; _dictReset(&src->ht[0]); + dst->rehashidx = 0; return DICT_OK; } @@ -210,10 +214,12 @@ int dictMerge(dict *dst, dict *src) while (de != nullptr) { dictEntry *deNext = de->next; + uint64_t h = dictHashKey(dst, de->key) & htDst.sizemask; de->next = htDst.table[h]; htDst.table[h] = de; htDst.used++; + de = deNext; src->ht[iht].used--; }