https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102810

            Bug ID: 102810
           Summary: Bogus Wstringop-overread warning when special
                    (integer) pointer values passed to array parameter of
                    a function
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ian at abbott dot org
  Target Milestone: ---

I don't know why this code produces a Wstringop-overread warning since it has
nothing to do with string operations.  Also, why is there a warning for
argument 2, but not for argument 1?

extern int foo(const int *a, const int b[]);

#define SPECIAL ((int *)2)

int main(void)
{
    foo(SPECIAL, SPECIAL);
}

int foo(const int a[], const int b[])
{
    return 0;
}

<source>: In function 'main':
<source>:7:5: warning: 'foo' reading 4 bytes from a region of size 0
[-Wstringop-overread]
    7 |     foo(SPECIAL, SPECIAL);
      |     ^~~~~~~~~~~~~~~~~~~~~
<source>:7:5: note: referencing argument 2 of type 'const int *'
<source>:10:5: note: in a call to function 'foo'
   10 | int foo(const int a[], const int b[])
      |     ^~~

Reply via email to