https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125335
Bug ID: 125335
Summary: False positive warning 'array subscript is partly
outside array bounds of'
Product: gcc
Version: 16.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: sadko4u at gmail dot com
Target Milestone: ---
Created attachment 64469
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64469&action=edit
The code snippet to reproduce the false positive warning
The code snippet in the description yields to the following set of warnings:
In member function ‘virtual wssize_t InBufStream::position()’,
inlined from ‘status_t InBufStream::do_wrap(IInStream*, size_t)’ at
snippet1.cpp:182:32,
inlined from ‘status_t InBufStream::open(const char*)’ at
snippet1.cpp:211:26:
snippet1.cpp:221:12: warning: array subscript ‘InBufStream[0]’ is partly
outside array bounds of ‘unsigned char [32]’ [-Warray-bounds=]
221 | return nPosition + nBufOff;
| ^~~~~~~~~
snippet1.cpp: In member function ‘status_t InBufStream::open(const char*)’:
snippet1.cpp:206:42: note: object of size 32 allocated by ‘operator new’
206 | InFileStream *ofs = new InFileStream();
| ^
In member function ‘virtual wssize_t InBufStream::position()’,
inlined from ‘status_t InBufStream::do_wrap(IInStream*, size_t)’ at
snippet1.cpp:182:32,
inlined from ‘status_t InBufStream::open(const char*)’ at
snippet1.cpp:211:26:
snippet1.cpp:221:24: warning: array subscript ‘InBufStream[0]’ is partly
outside array bounds of ‘unsigned char [32]’ [-Warray-bounds=]
221 | return nPosition + nBufOff;
| ^~~~~~~
snippet1.cpp: In member function ‘status_t InBufStream::open(const char*)’:
snippet1.cpp:206:42: note: object of size 32 allocated by ‘operator new’
206 | InFileStream *ofs = new InFileStream();
|
Compilation command:
g++ -O2 -Wall snippet1.cpp
Looks like the static analyzer treats virtual functions as non-virtual ones and
tries to inline their calls. But I'm not sure that I'm right in my suggestions.