From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CBEEC3858404; Mon, 18 Oct 2021 15:52:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CBEEC3858404 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/102810] [11/12 Regression] Bogus Wstringop-overread passing a smaller array to an array parameter without a bound Date: Mon, 18 Oct 2021 15:52:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.1.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc everconfirmed cf_reconfirmed_on component short_desc bug_status Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Oct 2021 15:52:15 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102810 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 i= sn't a more appropriate option yet. One should be added. The warning for argument 2 is a bug. With -Warray-parameter enabled, for t= he 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 t= hat the function expects an array argument with at least as many elements. A b= ug 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 f= or 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 ar= ray 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.)=