public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "fw at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-101415-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101415 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 != '\0' && __builtin_strlen (cptr) < 1024) { char *cp = __builtin_stpcpy (__nisgroup, cptr); if (cp[-1] != '.') __builtin_abort (); } return __nisgroup; } results in /tmp/t.c: In function ‘nis_local_group’: /tmp/t.c:10:13: error: array subscript -1 is outside array bounds of ‘char[1025] ’ [-Werror=array-bounds] 10 | if (cp[-1] != '.') | ~~^~~~ /tmp/t.c:4:15: note: at offset -1 into object ‘__nisgroup’ 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, which is not at the first byte of __nisgroup after the stpcpy. The glibc original does not have this check, so it is buggy, but the warning seems overly aggressive if it cannot detect non-empty strings for stpcpy.
next reply other threads:[~2021-07-11 13:04 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-11 13:04 fw at gcc dot gnu.org [this message] 2021-07-12 7:50 ` [Bug middle-end/101415] " rguenth at gcc dot gnu.org 2021-07-12 17:20 ` msebor at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-101415-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).