summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Martsum <tmartsum@gmail.com>2013-05-01 19:05:24 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-07-12 16:15:44 +0200
commit578fc87dffafd4211d7223bfbc3b1de086ccc45d (patch)
treed841aa0420420950ed18c36c94c525170c378863 /src
parentd24aa28b4c3841ecd35401c7c3064e68f7ec7589 (diff)
QVector - check if iterators arguments are valid (in debugmode)
This adds a check of the iterator values in erase and insert. Change-Id: I28e660153dbfc5f0054a5b25cba2c5725c678a81 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qvector.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index 489ee821b9..de64d7a670 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -238,7 +238,10 @@ private:
void defaultConstruct(T *from, T *to);
void copyConstruct(const T *srcFrom, const T *srcTo, T *dstFrom);
void destruct(T *from, T *to);
-
+ bool isValidIterator(const iterator &i) const
+ {
+ return (i <= d->end()) && (d->begin() <= i);
+ }
class AlignmentDummy { Data header; T array[1]; };
};
@@ -578,6 +581,8 @@ inline void QVector<T>::removeLast()
template <typename T>
typename QVector<T>::iterator QVector<T>::insert(iterator before, size_type n, const T &t)
{
+ Q_ASSERT_X(isValidIterator(before), "QVector::insert", "The specified iterator argument 'before' is invalid");
+
int offset = std::distance(d->begin(), before);
if (n != 0) {
const T copy(t);
@@ -611,6 +616,9 @@ typename QVector<T>::iterator QVector<T>::insert(iterator before, size_type n, c
template <typename T>
typename QVector<T>::iterator QVector<T>::erase(iterator abegin, iterator aend)
{
+ Q_ASSERT_X(isValidIterator(abegin), "QVector::erase", "The specified iterator argument 'abegin' is invalid");
+ Q_ASSERT_X(isValidIterator(aend), "QVector::erase", "The specified iterator argument 'aend' is invalid");
+
const int itemsToErase = aend - abegin;
if (!itemsToErase)