diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index e6f041fe3c..4eb05d63b6 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -641,6 +641,8 @@ Q_OUTOFLINE_TEMPLATE QList QList::mid(int pos, int alength) const if (pos == 0 && alength == size()) return *this; QList cpy; + if (alength <= 0) + return cpy; cpy.reserve(alength); cpy.d->end = alength; QT_TRY { diff --git a/tests/auto/qlist/tst_qlist.cpp b/tests/auto/qlist/tst_qlist.cpp index 496f3d9170..3901b6ffe8 100644 --- a/tests/auto/qlist/tst_qlist.cpp +++ b/tests/auto/qlist/tst_qlist.cpp @@ -200,6 +200,9 @@ void tst_QList::mid() const QCOMPARE(list.mid(3, 3), QList() << "bak" << "buck" << "hello"); + + QList list1; + QCOMPARE(list1.mid(1, 1).length(), 0); } void tst_QList::at() const