Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.3
-
None
-
8befc4982a32752e48c82cacbed045e7336a3569
Description
Since Qt 4.7, QList::mid has been partially rewritten (surely for optimization reasons).
However, when used with bad indices on an empty list, it can result in overwritting QListData::shared_null making new QLists unusable.
In Qt 4.6, it returned an empty list because the loop was not entered when indices where wrong.
Don't know why QList::mid has been rewritten but not QVector ??
The following code reproduces the problem:
#include <stdio.h>
#include <QList>
void main()
{
QList<int> indices;
printf("NN1 = %d\n", indices.length());
QList<int> ind2 = indices.mid(1,1);
printf("NN2 = %d\n", ind2.length());
QList<int> ind3;
printf("NN3 = %d\n", ind3.length());
}
Will print out:
$ ./aa.exe
NN1 = 0
NN2 = -1
NN3 = -1
All the lists are broken, and you're not so far from the crash (for example using foreach...), even if you use a completly different list in a different portion of the source.