summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Martsum <tmartsum@gmail.com>2013-05-03 16:13:55 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-07-12 16:15:44 +0200
commit1c0a924a2e520b5ff36a6d9eba6aca8fa57e2eab (patch)
tree2aaa41e1c1d65b74589be68fd829ea553f99dd83 /src
parentca3d8411b29bb4cede1af9b2e871b1ba3dc6f4cf (diff)
QHash - checks if iterator argument is valid (in debugmode)
This checks if the iterator argument in erase is valid in debug mode. Change-Id: I8768f4263d1464ff78986a1a30702e210e561dc1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qhash.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index e99a67d1e3..0124b787db 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -509,6 +509,24 @@ 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
+ }
};
@@ -831,6 +849,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;