diff options
author | Thorbjørn Martsum <tmartsum@gmail.com> | 2013-05-03 06:45:10 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-12 16:15:44 +0200 |
commit | 012d3750e79ebe4ceaffc0aa2a6bcccd02d47614 (patch) | |
tree | cd24a59a168f614ec84323edc261f38fe121b0ee /src/corelib/tools/qset.h | |
parent | 1c0a924a2e520b5ff36a6d9eba6aca8fa57e2eab (diff) |
QSet - check if iterator argument is valid (in debugmode)
This adds a check on erase that the iterator is from the set.
Change-Id: I9f4e127d53a5b1f5f8c70652604f1f5574c73688
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qset.h')
-rw-r--r-- | src/corelib/tools/qset.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index 265861198d..ad2f91b983 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -181,7 +181,10 @@ public: inline const_iterator cend() const { return q_hash.end(); } inline const_iterator constEnd() const { return q_hash.constEnd(); } iterator erase(iterator i) - { return q_hash.erase(reinterpret_cast<typename Hash::iterator &>(i)); } + { + Q_ASSERT_X(isValidIterator(i), "QSet::erase", "The specified const_iterator argument 'i' is invalid"); + return q_hash.erase(reinterpret_cast<typename Hash::iterator &>(i)); + } // more Qt typedef iterator Iterator; @@ -234,6 +237,10 @@ public: private: Hash q_hash; + bool isValidIterator(const iterator &i) const + { + return q_hash.isValidIterator(reinterpret_cast<const typename Hash::iterator&>(i)); + } }; template <class T> |