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

            Bug ID: 84397
           Summary: missing -Wstringop-truncation on strncpy into a
                    multidimensional array
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The -Wstringop-truncation detects the potential string truncation in the first
strncpy call below but fails to detect the similar problem in the second call.

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

void f0 (const char *s)
{
  __builtin_strncpy (a[0], s, sizeof a[0]);   // missing -Wstringop-truncation
}

void f1 (const char *s)
{
  __builtin_strncpy (a[1], s, sizeof a[1]);   // -Wstringop-truncation (good)
}

void fi (const char *s, int i)
{
  __builtin_strncpy (a[i], s, sizeof a[i]);   // missing -Wstringop-truncation
}

a.c: In function ‘f1’:
a.c:10:3: warning: ‘__builtin_strncpy’ specified bound 7 equals destination
size [-Wstringop-truncation]
   __builtin_strncpy (a[1], s, sizeof a[1]);   // -Wstringop-truncation (good)
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to