From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 222E93854833; Sun, 11 Jul 2021 13:04:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 222E93854833 From: "fw at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/101415] New: [12 Regression] Bogus -Warray-bounds warning with stpcpy Date: Sun, 11 Jul 2021 13:04:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: fw at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone Message-ID: 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: Sun, 11 Jul 2021 13:04:49 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101415 Bug ID: 101415 Summary: [12 Regression] Bogus -Warray-bounds warning with stpcpy Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: fw at gcc dot gnu.org Target Milestone: --- This (derived from the glibc function of the same name): char * nis_local_group (char *cptr) { static char __nisgroup[1025]; if (*cptr !=3D '\0' && __builtin_strlen (cptr) < 1024) { char *cp =3D __builtin_stpcpy (__nisgroup, cptr); if (cp[-1] !=3D '.') __builtin_abort (); } return __nisgroup; } results in=20 /tmp/t.c: In function =E2=80=98nis_local_group=E2=80=99: /tmp/t.c:10:13: error: array subscript -1 is outside array bounds of =E2=80=98char[1025] =E2=80=99 [-Werror=3Darray-bounds] 10 | if (cp[-1] !=3D '.') | ~~^~~~ /tmp/t.c:4:15: note: at offset -1 into object =E2=80=98__nisgroup=E2=80=99 = of size 1025 4 | static char __nisgroup[1025]; | ^~~~~~~~~~ with -O2 -Wall on x86-64 gcc version 12.0.0 20210711 (experimental) [master revision :97a8a2829:269256f33c51222167ad461f775d5468bb5ecaf5]. The warning is bogus because stpcpy returns a pointer to the NUL byte, whic= h is not at the first byte of __nisgroup after the stpcpy. The glibc original do= es not have this check, so it is buggy, but the warning seems overly aggressiv= e if it cannot detect non-empty strings for stpcpy.=