summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Martsum <tmartsum@gmail.com>2013-05-06 16:47:02 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-07-12 16:15:44 +0200
commit659f62981f8fa475e138a6c47f3b50adaacba53e (patch)
tree5d602ae4363639609267b15211caf81b184fdd0f /src
parent012d3750e79ebe4ceaffc0aa2a6bcccd02d47614 (diff)
QVarLengthArray - check if iterators arguments are valid (in debugmode)
This add checks on iterators on insert and erase. Change-Id: I41d96e038d74668cc1df10b6d42cde4b82f8a696 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qvarlengtharray.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index 825e05ae1b..d9b85c4173 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -192,6 +192,11 @@ private:
qint64 q_for_alignment_1;
double q_for_alignment_2;
};
+
+ bool isValidIterator(const const_iterator &i) const
+ {
+ return (i <= constEnd()) && (constBegin() <= i);
+ }
};
template <class T, int Prealloc>
@@ -355,6 +360,8 @@ inline void QVarLengthArray<T, Prealloc>::replace(int i, const T &t)
template <class T, int Prealloc>
Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::insert(const_iterator before, size_type n, const T &t)
{
+ Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid");
+
int offset = int(before - ptr);
if (n != 0) {
resize(s + n);
@@ -382,6 +389,9 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthA
template <class T, int Prealloc>
Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::erase(const_iterator abegin, const_iterator aend)
{
+ Q_ASSERT_X(isValidIterator(abegin), "QVarLengthArray::insert", "The specified const_iterator argument 'abegin' is invalid");
+ Q_ASSERT_X(isValidIterator(aend), "QVarLengthArray::insert", "The specified const_iterator argument 'aend' is invalid");
+
int f = int(abegin - ptr);
int l = int(aend - ptr);
int n = l - f;