Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.4.1, 5.1.0 Beta 1
-
None
-
873ae53d47b34e51c0e44303499fad23737f9e5b
Description
The problem arised this way:
QBitArray a; a.resize (0); qDebug () << a.count () << a.count (true) << a.count (false);
Expected and usual result is 0 0 0, but sometimes it is: 0 1 -1
To me, the reason is this (qbitarray.cpp):
void QBitArray::resize(int size) { if (!size) { d.resize(0); /* QByteArray is resized to 0 */ .... }
And than:
int QBitArray::count(bool on) const { int numBits = 0; int len = size(); const quint8 *bits = reinterpret_cast<const quint8 *>(d.data()) + 1; /* bits now points past the end of allocated memory */ ....... while (len >= 0) { if (bits[len / 8] & (1 << ((len - 1) & 7))) /* here we access some unknown memory */ ++numBits; --len; } return on ? numBits : size() - numBits; }