Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.2.3, 6.5.1
-
None
-
-
8739963c8 (dev), f003d43eb (6.6)
Description
A compile error in qbitarray.h, could be a compiler bug, or an actual error that isn't detected when the code is unfolded. To reproduce, pass something unsigned to QBitArray::testBit() - could be simpler ways to reproduce also. In our code we declared an enum of type unsigned, and passed one of the values to QBitArray::testBit().
qt/include/QtCore/qbitarray.h:86:10: error: array subscript 1 is outside array bounds of 'const char [1]' [-Werror=array-bounds=] 86 | return (*(reinterpret_cast<const uchar*>(d.constData())+1+(i>>3)) & (1 << (i & 7))) != 0; }
Code in question:
inline bool QBitArray::testBit(qsizetype i) const { Q_ASSERT(size_t(i) < size_t(size())); return (*(reinterpret_cast<const uchar*>(d.constData())+1+(i>>3)) & (1 << (i & 7))) != 0; }
Unfolding the code removes the compile error, note that this generates the exact same assembly when built:
inline bool QBitArray::testBit(qsizetype i) const { Q_ASSERT(size_t(i) < size_t(size())); const auto *castedDataPointer = reinterpret_cast<const uchar*>(d.constData()); castedDataPointer += 1 + (i >> 3); const auto dataByte = *castedDataPointer; const auto bitLocation = 1 << (i & 7); return (dataByte & bitLocation) != 0; }
Attachments
For Gerrit Dashboard: QTBUG-118631 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
516640,2 | QBitArray: fix GCC 13 warnings by improving code | dev | qt/qtbase | Status: MERGED | +2 | 0 |
516983,2 | QBitArray: fix GCC 13 warnings by improving code | 6.6 | qt/qtbase | Status: MERGED | +2 | 0 |
517498,2 | Build with QT5_NULL_STRINGS == 0 | dev | qt/qtbase | Status: ABANDONED | 0 | 0 |