Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.12.4, 5.13.0
-
None
-
-
6ce9404a6e7ad6ba3ff37f6890fe400c643c3d52 (qt/qtbase/5.12)
Description
When initializing a QBitArray using function:
static QBitArray fromBits(const char *data, qsizetype len);
The resulting bit array isn't always properly initialized.
I wrote an example where I have one byte but want to use only 5 bits.
// Example code #include <QCoreApplication> #include <QBitArray> #include <stdio.h> int main(int argc, char* argv[]) { QCoreApplication a(argc, argv); char c = 0xff; const int nbits = 5; const QBitArray ba = QBitArray::fromBits(&c, nbits); for(int b=0 ; b<nbits ; ++b) printf("%d ", ba.testBit(b) ? 1 : 0); fflush(stdout); return a.exec(); }
The above code produces the following result:
1 1 1 0 0
When in fact it should produce:
1 1 1 1 1
This happens always in the last byte of the array, I was able to reproduce this in arrays of several sizes, this example has one byte only for simplicity.