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

            Bug ID: 86552
           Summary: missing warning for reading past the end of non-string
                    arrays
           Product: gcc
           Version: 9.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: ---

GCC silently accepts array declarations with string initializers that contain
an extra element (the terminating nul) that doesn't fit into the array, and
also silently allows such arrays to be used as arguments to functions that
require string arguments.

It would be helpful to diagnose the initialization.  Regardless of diagnostics
for those, GCC should also diagnose uses of such arrays when possible (e.g., in
the constant cases).  This should be done regardless of the form of the
initialization (i.e., using a string literal or using a series of characters,
as in const char a[3] = { '1', '2', '3' };).

const char a[3] = "123";   // no warning

int f (void)
{
  return __builtin_strlen (a);   // missing warning
}

void g (char *d)
{
  __builtin_strcpy (d, a);   // missing warning
}

Reply via email to