From 4ddc5163823b4fb75ab7050bf351310c8e3929ea Mon Sep 17 00:00:00 2001 From: John Sully Date: Thu, 4 Jun 2020 00:22:59 -0400 Subject: [PATCH] Extra debug checks in dictmerge Former-commit-id: 839b2a151e6bad67017de87d7a637359f6ae63d1 --- src/dict.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/dict.cpp b/src/dict.cpp index 7434804af..c99e7dd5b 100644 --- a/src/dict.cpp +++ b/src/dict.cpp @@ -190,6 +190,7 @@ int dictMerge(dict *dst, dict *src) return DICT_OK; } + size_t expectedSize = dictSize(src) + dictSize(dst); if (dictSize(src) > dictSize(dst)) { std::swap(*dst, *src); @@ -198,10 +199,18 @@ int dictMerge(dict *dst, dict *src) if (!dictIsRehashing(dst) && !dictIsRehashing(src)) { - dst->ht[1] = dst->ht[0]; - dst->ht[0] = src->ht[0]; + if (dst->ht[0].size >= src->ht[0].size) + { + dst->ht[1] = dst->ht[0]; + dst->ht[0] = src->ht[0]; + } + else + { + dst->ht[1] = src->ht[0]; + } _dictReset(&src->ht[0]); dst->rehashidx = 0; + assert((dictSize(src)+dictSize(dst)) == expectedSize); return DICT_OK; } @@ -229,6 +238,7 @@ int dictMerge(dict *dst, dict *src) } } } + assert((dictSize(src)+dictSize(dst)) == expectedSize); return DICT_OK; }