summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qhash.h3
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp17
2 files changed, 19 insertions, 1 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index ecbdfe4fb8..49c9ce1d41 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -500,8 +500,9 @@ struct Data
bool resized = numBuckets != other.numBuckets;
size_t nSpans = (numBuckets + Span::LocalBucketMask) / Span::NEntries;
spans = new Span[nSpans];
+ size_t otherNSpans = (other.numBuckets + Span::LocalBucketMask) / Span::NEntries;
- for (size_t s = 0; s < nSpans; ++s) {
+ for (size_t s = 0; s < otherNSpans; ++s) {
const Span &span = other.spans[s];
for (size_t index = 0; index < Span::NEntries; ++index) {
if (!span.hasNode(index))
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index 3c873d093e..576a1c6107 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -93,6 +93,8 @@ private slots:
void removeInEmptyHash();
void valueInEmptyHash();
void fineTuningInEmptyHash();
+
+ void reserveShared();
};
struct IdentityTracker {
@@ -2598,5 +2600,20 @@ void tst_QHash::fineTuningInEmptyHash()
QVERIFY(hash.capacity() > 0);
}
+void tst_QHash::reserveShared()
+{
+ QHash<char, char> hash;
+ hash.insert('c', 'c');
+ auto hash2 = hash;
+
+ QCOMPARE(hash2.capacity(), hash.capacity());
+ auto oldCap = hash.capacity();
+
+ hash2.reserve(100); // This shouldn't crash
+
+ QVERIFY(hash2.capacity() >= 100);
+ QCOMPARE(hash.capacity(), oldCap);
+}
+
QTEST_APPLESS_MAIN(tst_QHash)
#include "tst_qhash.moc"