public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/101415] New: [12 Regression] Bogus -Warray-bounds warning with stpcpy
@ 2021-07-11 13:04 fw at gcc dot gnu.org
  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
  0 siblings, 2 replies; 3+ messages in thread
From: fw at gcc dot gnu.org @ 2021-07-11 13:04 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/101415] [12 Regression] Bogus -Warray-bounds warning with stpcpy
  2021-07-11 13:04 [Bug middle-end/101415] New: [12 Regression] Bogus -Warray-bounds warning with stpcpy fw at gcc dot gnu.org
@ 2021-07-12  7:50 ` rguenth at gcc dot gnu.org
  2021-07-12 17:20 ` msebor at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-12  7:50 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/101415] [12 Regression] Bogus -Warray-bounds warning with stpcpy
  2021-07-11 13:04 [Bug middle-end/101415] New: [12 Regression] Bogus -Warray-bounds warning with stpcpy fw at gcc dot gnu.org
  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
  1 sibling, 0 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-07-12 17:20 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
                 CC|                            |msebor at gcc dot gnu.org
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
I'm tracking this in pr101397.

*** This bug has been marked as a duplicate of bug 101397 ***

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-12 17:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-11 13:04 [Bug middle-end/101415] New: [12 Regression] Bogus -Warray-bounds warning with stpcpy fw at gcc dot gnu.org
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

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).