Bug ID: 84395
           Summary: -Wstringop-truncation where -Wstringop-overflow is
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot
          Reporter: msebor at gcc dot
  Target Milestone: ---

The test case below triggers what looks like a bogus -Wstringop-truncation
warning when it instead should trigger -Wstringop-overflow.

The -Wstringop-truncation warning indicates that the checker considers the size
of the entire array (i.e., 3 * 7 chars) when it should consider the size of the
subarray a[i] (i.e., 7 chars).

The missing -Wstringop-overflow suggests this checker is doing the same.

$ cat t.c && gcc -O2 -S -Wall -Wextra t.c
char a[3][7];

void f (const char *s, int i)
  __builtin_strncpy (a[i], s, 21);   // -Wstringop-truncation but no
  a[i][6] = 0;
t.c: In function ‘f’:
t.c:5:3: warning: ‘__builtin_strncpy’ specified bound 21 equals destination
size [-Wstringop-truncation]
   __builtin_strncpy (a[i], s, 21);   // -Wstringop-truncation but no

Reply via email to