Details
-
Type:
Bug
-
Status: Closed
-
Priority:
P2: Important
-
Resolution: Done
-
Affects Version/s: 5.12.4, 5.13.0
-
Fix Version/s: 5.12.5, 5.14.0 Alpha
-
Component/s: Core: Other
-
Labels:None
-
Platform/s:
-
Commits: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.
Attachments
For Gerrit Dashboard: QTBUG-77285 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
269368,3 | QBitArray: fix fromBits() and actually test it | 5.12 | qt/qtbase | Status: MERGED | +2 | 0 |