From ef1905aebc4c4961c859bd781398dc6cea89d3a0 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 15 Oct 2020 02:32:00 +0200 Subject: [PATCH] QMultiHash: fix operator== An empty QMultiHash can still have an allocated dpointer, so we can't desume that two hashes are different because one has a dpointer and the other doesn't. Compares the sizes first, and infer that equal size, and non-zero size, mean both have a dpointer. Fixes: QTBUG-87575 Change-Id: I2e206bd071c02fb8970a4e77f8b0d29ad7e58bbe Reviewed-by: Lars Knoll Reviewed-by: Thiago Macieira --- src/corelib/tools/qhash.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index c6b82dbd338..046dbddb572 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -1229,9 +1229,14 @@ public: { if (d == other.d) return true; - if (!d || ! other.d) + if (m_size != other.m_size) return false; - if (m_size != other.m_size || d->size != other.d->size) + if (m_size == 0) + return true; + // equal size, and both non-zero size => d pointers allocated for both + Q_ASSERT(d); + Q_ASSERT(other.d); + if (d->size != other.d->size) return false; for (auto it = other.d->begin(); it != other.d->end(); ++it) { auto i = d->find(it.node()->key);