Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
6.2.0
-
None
-
-
d1626ca6b0 (qt/qtbase/dev) d1626ca6b0 (qt/tqtc-qtbase/dev) b968f37b08 (qt/qtbase/6.3) 4e30362dd0 (qt/qtbase/6.2) 4e30362dd0 (qt/tqtc-qtbase/6.2) b968f37b08 (qt/tqtc-qtbase/6.3)
Description
Example:
QHash<QString, QString> hash; for (const QString & key: QStringList{ "a","b","c","d","e","f","g","h" }) { hash.insert(key, "value of " + key); } for (auto it = hash.keyBegin(); it != hash.keyEnd(); ++it) { qWarning() << *it << " --> " << hash[*it]; }
generates the following output (and is aborted if address sanitizer is active):
"g" --> "" "a" --> "value of a" "c" --> "value of c" "e" --> "value of e" "d" --> "value of d" "h" --> "value of h" "f" --> "value of f" "b" --> "value of b"
Problem:
- non-const operator[] calls d->findOrInsert(key)
- findOrInsert() increases hash size, even if key exists
- the realloc destroys the iterator
Expected:
Only resize hash if the key is not found and must be inserted.