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

            Bug ID: 94626
           Summary: -Wstringop-truncation warning should mention
                    attribute((nonstring))
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: allison.karlitskaya at redhat dot com
  Target Milestone: ---

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

Consider this code:

{
  struct lastlog entry;

  strncpy (entry.ll_host, rhost, sizeof entry.ll_host);
  /* fill other fields */

  /* write record to the lastlog */
}

GCC 8 will warn like so:

/usr/include/bits/string_fortified.h:106:10: warning: '__builtin_strncpy'
specified bound 256 equals destination size [-Wstringop-truncation]

which is pretty frustrating, because I'm using strncpy() as intended: for a
field where nul-termination is optional.  Of course the bound is equal to the
destination size.  That's what I want!

A more helpful warning (and one that would have saved me considerable time
during the last weeks) would include a mention of the fact that the nonstring
attribute is missing on the destination.

This warning would have been much more helpful for helping me file the actual
bug in this case: the system header has this attribute for utmp, but they
missed adding it for lastlog.

Reply via email to