qt6-bb10/tests/auto/corelib/tools/qbitarray
Marc Mutz c6aa399d06 QBitArray: avoid overflow in size-to-storage calculations
Unlike other containers, a QBitArray's size() is not limited by
storage, but, esp. on 32-bit platforms, its size_type: A INT_MAX
size() QBitArray only requires 256MiB of storage.

So we can't rely on "won't happen in practice" here and need to avoid
the potential UB (signed overflow) in the (size + 7) / 8
logical-to-storage-size calculation by using unsigned arithmetic.

Use the opportunity to Extract Methods storage_size() and
allocation_size(), which differ by one (d[[0] contains the size() mod
8), making it clear what's what.

[ChangeLog][QtCore][QBitArray] Fixed a bug with QBitArrays whose
size() came within 7 of the size_type's maximum.

Pick-to: 6.7 6.6 6.5 6.2 5.15
Change-Id: I5d94bae9c9c210ba1e36f8cf03609125c81bd15d
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
2024-01-30 22:28:19 +01:00
..
.gitignore Moving relevant tests to corelib/tools 2011-09-01 13:07:23 +02:00
CMakeLists.txt CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
tst_qbitarray.cpp QBitArray: avoid overflow in size-to-storage calculations 2024-01-30 22:28:19 +01:00