https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102810
Martin Sebor changed:
What|Removed |Added
CC||msebor at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed||2021-10-18
Component|c |middle-end
Summary|Bogus Wstringop-overread|[11/12 Regression] Bogus
|warning when special|Wstringop-overread passing
|(integer) pointer values|a smaller array to an array
|passed to array parameter |parameter without a bound
|of a function |
Status|UNCONFIRMED |NEW
--- Comment #1 from Martin Sebor ---
GCC issues the -Wstringop-xxx warnings in this context only because there isn't
a more appropriate option yet. One should be added.
The warning for argument 2 is a bug. With -Warray-parameter enabled, for the
purposes of out-of-bounds access detection, GCC treats function parameters
declared using the array form (as in void f (int a[2]);) as an indication that
the function expects an array argument with at least as many elements. A bug
in the code applies the same logic to an array parameter declared with no
bounds, as in the example. I confirm this report for this problem.
With the following snippet, a read access warning should only be expected for
the third argument:
extern int foo(const int *a, const int b[], const int c[1]);
int main (void)
{
foo ((int*)2, (int*)2, (int*2));
}
The warning in this instance is issued because functions that take const array
parameters with non-zero bound are assumed to read as many elements from the
parameters as the bound indicates. Because (int*)2 is not a pointer to an
array with at least two elements (or a valid pointer at all), the warning
triggers.
(Note that using invalid pointers like (int*)2 in any expression, including
assigning them to function parameters, is undefined and may be diagnosed in the
future regardless of the context they're used in, including in in arguments 1
and 2 above.)