Fix a regression in QList::mid()
authorLiang Qi <liang.qi@nokia.com>
Mon, 16 May 2011 08:48:05 +0000 (10:48 +0200)
committerQt Continuous Integration System <qt-info@nokia.com>
Fri, 27 May 2011 09:06:52 +0000 (11:06 +0200)
It doesn't need to copy anything when pos is after size().

Task-number: QTBUG-19164
Reviewed-by: Oswald Buddenhagen
(cherry picked from commit 8befc4982a32752e48c82cacbed045e7336a3569)

Change-Id: Iccac75842616f0d41e457e844a15d1a3ccfeb642
Reviewed-on: http://codereview.qt.nokia.com/164
Reviewed-by: Liang Qi <liang.qi@nokia.com>
src/corelib/tools/qlist.h
tests/auto/qlist/tst_qlist.cpp

index e6f041f..4eb05d6 100644 (file)
@@ -641,6 +641,8 @@ Q_OUTOFLINE_TEMPLATE QList<T> QList<T>::mid(int pos, int alength) const
     if (pos == 0 && alength == size())
         return *this;
     QList<T> cpy;
+    if (alength <= 0)
+        return cpy;
     cpy.reserve(alength);
     cpy.d->end = alength;
     QT_TRY {
index 496f3d9..3901b6f 100644 (file)
@@ -200,6 +200,9 @@ void tst_QList::mid() const
 
     QCOMPARE(list.mid(3, 3),
              QList<QString>() << "bak" << "buck" << "hello");
+
+    QList<int> list1;
+    QCOMPARE(list1.mid(1, 1).length(), 0);
 }
 
 void tst_QList::at() const