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

            Bug ID: 86121
           Summary: [9 Regression] missing -Wstringop-overflow on strcpy
                    followed by strcat
           Product: gcc
           Version: 8.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 7 and 8 correctly diagnose the buffer overflow in the test case below by
issuing -Wstringop-overflow.  However, in the current trunk of GCC 9 the
warning fails to detect the same bug (GCC 9 issues -Warray-bounds instead).

$ cat c.c && gcc -O2 -S -Wstringop-overflow -fdump-tree-optimized=/dev/stdout
c.c
#define bos1(p) __builtin_object_size (p, 1)
#define strcat(d, s) __builtin___strcat_chk (d, s, bos1 (d))
#define strcpy(d, s) __builtin___strcpy_chk (d, s, bos1 (d))

char a[2];

void test_strcpy_strcat_2 (void)
{
  strcpy (a, "12");
  strcat (a, "3");
}

;; Function test_strcpy_strcat_2 (test_strcpy_strcat_2, funcdef_no=0,
decl_uid=1897, cgraph_uid=1, symbol_order=1)

test_strcpy_strcat_2 ()
{
  <bb 2> [local count: 1073741825]:
  MEM[(char * {ref-all})&a] = MEM[(char * {ref-all})"12"];
  MEM[(char * {ref-all})&a + 2B] = MEM[(char * {ref-all})"3"];
  return;

}

Reply via email to