summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMÃ¥rten Nordheim <marten.nordheim@qt.io>2021-06-16 11:40:04 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-18 09:49:58 +0000
commit66aa4c86f4303dba48910c39ed0908818bf5dc6f (patch)
tree6bbf085cc046ad479fd63193232dbe322c0c86e0 /src
parent9f459dee1fb7b2fd429e827a0195c4e9a39003b2 (diff)
QHash: Fix erase() edge-case
When the element you want to erase is the last element AND the next element (element 0), when rehashed, would be relocated to the last element, this leads to the state below. Which is similar to a test in tst_qhash for some seeds. auto it = hash.begin + (hash.size - 1) it = hash.erase(it) it != hash.end By forcing the iterator to increment if we were erasing the last element we always end up with a pointer which is equal to hash.end Befriend the tst_qhash class so we can set the seed to a known-bad one Change-Id: Ie0b175003a2acb175ef5e3ab5a984e010f65d986 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit ea7d87b5b59ded22b145ecbb4dd648ecfd1abbdd) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qhash.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 4fb68ba0b5..1a793e6163 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -51,6 +51,8 @@
#include <initializer_list>
#include <functional> // for std::hash
+class tst_QHash; // for befriending
+
QT_BEGIN_NAMESPACE
struct QHashDummyValue
@@ -680,7 +682,7 @@ struct Data
}
// return correct position of the next element
- if (!spans[span].hasNode(index))
+ if (bucket == numBuckets - 1 || !spans[span].hasNode(index))
++it;
return it;
}
@@ -740,6 +742,7 @@ class QHash
using Data = QHashPrivate::Data<Node>;
friend class QSet<Key>;
friend class QMultiHash<Key, T>;
+ friend tst_QHash;
Data *d = nullptr;