Don't operate on bogus data, assert on preconditions instead
authorJoão Abecasis <joao.abecasis@nokia.com>
Fri, 8 Jun 2012 13:25:26 +0000 (15:25 +0200)
committerQt by Nokia <qt-info@nokia.com>
Sat, 23 Jun 2012 12:16:33 +0000 (14:16 +0200)
commit796f85b611da5d689e08398e027b130824720a23
tree998eecf44a73d6debff1eae10e657a5a8a7d8539
parent86ae3809a96e298d2e4c643c90417eb01be87fd9
Don't operate on bogus data, assert on preconditions instead

QVector::erase shouldn't try to make sense of iterators it doesn't own,
so the validation being done here is bogus and dangerous. Instead, it's
preferrable to assert, the user needs to ensure proper ownership.

The case of erasing an empty sequence is not checked for preconditions
to allow

    QVector v;
    v.erase(v.begin(), v.end());

, while being stricter on other uses.

Autotests were using ill-formed calls to the single argument erase()
function on an empty vector and were fixed. This function erases exactly
one element, the one pointed to by abegin and require the element exist
and be valid.

Change-Id: I5f1a6d0d8da072eae0c73a3012620c4ce1065cf0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/tools/qvector.h
tests/auto/corelib/tools/qvector/tst_qvector.cpp