[Development] Warnign when building qtbase: -Walloc-size-larger-than

Thiago Macieira thiago.macieira at intel.com
Mon Feb 6 20:37:07 CET 2023


On Monday, 6 February 2023 11:21:13 PST Lisandro Damián Nicanor Pérez Meyer 
wrote:
> When building qtbase 6.4.2 on Debian I see:
> 
> In member function ‘__ct ’,
>     inlined from ‘detached’ at
> ./obj-x86_64-linux-gnu/include/QtCore/../../../src/corelib/tools/qhash.h:57
> 5:20, inlined from ‘detach’ at
> ./obj-x86_64-linux-gnu/include/QtCore/../../../src/corelib/tools/qhash.h:15
> 01:75:
> ./obj-x86_64-linux-gnu/include/QtCore/../../../src/corelib/tools/qhash.h:55
> 9:17: warning: argument 1 value ‘18446744073709551615’ exceeds maximum
> object size 9223372036854775807 [-Walloc-size-larger-than=]
> /usr/include/c++/12/new: In member function ‘detach’:
> /usr/include/c++/12/new:128:26: note: in a call to allocation function
> ‘operator new []’ declared here 128 | _GLIBCXX_NODISCARD void* operator
> new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
> 
> Is this something to be worried about?

No. It's a false positive. The value that GCC is reporting is also impossible:

        size_t nSpans = numBuckets >> SpanConstants::SpanShift;
        spans = new Span[nSpans];

numBuckets is a size_t, so shifting it right will shift 7 (SpanShift) zeroes 
in. That means the maximum value that nSpans could assume is 2^(64-7) - 1.

If you multiply that value by sizeof(Span) == 144, that would overflow the 
size_t though.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5167 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20230206/18a35eed/attachment.bin>


More information about the Development mailing list