https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126780
Bug ID: 126780
Summary: false-positive -Wanalyzer-out-of-bounds with
__attribute__((access))
Product: gcc
Version: 16.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: diagnostics
Assignee: dmalcolm at redhat dot com
Reporter: marian.buschsieweke at posteo dot net
Target Milestone: ---
Minimum reproducer:
__attribute__((access(write_only, 1, 2)))
void foo(void *ptr, unsigned size);
void bar(void)
{
static char buf[1024];
foo(buf + 4, sizeof(buf) - 4);
}
When compiled with `-Os -fanalyzer`, an out of-bounds read is detected. The
static analyzer is completly ignoring the second argument here and assuming an
1024 byte write no matter what. The issue is present in both GCC 16.1 and 16.2.
See https://godbolt.org/z/7dE1roqn1