public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/94208] New: missing warning on passing unterminated local array to string functions
@ 2020-03-17 22:21 msebor at gcc dot gnu.org
  2024-04-07  5:25 ` [Bug middle-end/94208] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-03-17 22:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94208
           Summary: missing warning on passing unterminated local array to
                    string functions
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC 10 diagnoses only one out of the three invalid uses of the unterminated
array below.  The strlen pass "knows" the number of non-zero characters in each
of the local arrays and it also knows it's equal to the size of the array so it
has all it needs to diagnose the calls.

The problem is the same with other string functions (e.g., strlen or sprintf)
so a complete fix should extend the warning to all of them.

$ cat t.c && gcc -O2 -S -Wall -Wextra -Wpedantic
-fdump-tree-optimized=/dev/stdout t.c
const char a[4] = { '1', '2', '3', '4' };

void f0 (char *d)
{
  __builtin_strcpy (d, a);   // warning (good)
}

void f1 (char *d)
{
  const char a[4] = { '1', '2', '3', '4' };
  __builtin_strcpy (d, a);   // missing warning
}

void f2 (char *d)
{
  __builtin_strcpy (d, (char[4]){ '1', '2', '3', '4' });   // missing warning
}
t.c: In function ‘f0’:
t.c:5:3: warning: ‘strcpy’ argument missing terminating nul
[-Wstringop-overflow=]
    5 |   __builtin_strcpy (d, a);   // warning (good)
      |   ^~~~~~~~~~~~~~~~~~~~~~~
t.c:1:12: note: referenced argument declared here
    1 | const char a[4] = { '1', '2', '3', '4' };
      |            ^

;; Function f0 (f0, funcdef_no=0, decl_uid=1931, cgraph_uid=1, symbol_order=1)

f0 (char * d)
{
  <bb 2> [local count: 1073741824]:
  __builtin_strcpy (d_2(D), &a); [tail call]
  return;

}



;; Function f1 (f1, funcdef_no=1, decl_uid=1934, cgraph_uid=2, symbol_order=2)

f1 (char * d)
{
  const char a[4];

  <bb 2> [local count: 1073741824]:
  a = "1234";
  __builtin_strcpy (d_3(D), &a);
  a ={v} {CLOBBER};
  return;

}



;; Function f2 (f2, funcdef_no=2, decl_uid=1938, cgraph_uid=3, symbol_order=3)

f2 (char * d)
{
  char D.1940[4];

  <bb 2> [local count: 1073741824]:
  MEM <unsigned int> [(char *)&D.1940] = 875770417;
  __builtin_strcpy (d_6(D), &D.1940);
  D.1940 ={v} {CLOBBER};
  return;

}

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

* [Bug middle-end/94208] missing warning on passing unterminated local array to string functions
  2020-03-17 22:21 [Bug middle-end/94208] New: missing warning on passing unterminated local array to string functions msebor at gcc dot gnu.org
@ 2024-04-07  5:25 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-07  5:25 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-04-07
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

end of thread, other threads:[~2024-04-07  5:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-17 22:21 [Bug middle-end/94208] New: missing warning on passing unterminated local array to string functions msebor at gcc dot gnu.org
2024-04-07  5:25 ` [Bug middle-end/94208] " pinskia 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).