diff options
Diffstat (limited to 'src/corelib/tools/qhash.h')
-rw-r--r-- | src/corelib/tools/qhash.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index e99a67d1e3..25029afe1f 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -509,6 +509,25 @@ private: static void deleteNode2(QHashData::Node *node); static void duplicateNode(QHashData::Node *originalNode, void *newNode); + + bool isValidIterator(const iterator &it) const + { +#if defined(QT_DEBUG) && !defined(Q_HASH_NO_ITERATOR_DEBUG) + union { + QHashData *iteratorHashData; + QHashData::Node *node; + }; + node = it.i; + while (node->next) + node = node->next; + + return (iteratorHashData == d); +#else + Q_UNUSED(it); + return true; +#endif + } + friend class QSet<Key>; }; @@ -831,6 +850,8 @@ Q_OUTOFLINE_TEMPLATE T QHash<Key, T>::take(const Key &akey) template <class Key, class T> Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::iterator QHash<Key, T>::erase(iterator it) { + Q_ASSERT_X(isValidIterator(it), "QHash::erase", "The specified const_iterator argument 'it' is invalid"); + if (it == iterator(e)) return it; |