QHash: avoid crashing when reserving on a shared hash
Pick-to: 6.2 Change-Id: I21ad13fa223bd5a2c61112e790965093a2750268 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
e3f05981cb
commit
323b97ccae
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue