[PATCH] add attribute nonstring

Martin Sebor msebor@gmail.com
Fri Nov 10 17:31:00 GMT 2017


The latest revision of GCC 8.0 adds a -Wstringop-truncation option
to detect common misuses of the strncpy and strncat functions that
may truncate the copy and leave the result without a terminating
nul character.

On its own, the warning cannot distinguish the intended and safe
uses of the functions (to fill a buffer with data) from the
incorrect and unsafe ones (to make a "bounded" copy of a string).
Because the misuses have become prevalent and the correct/intended
uses are in a minority, GCC has added a new attribute called
nonstring to annotate character arrays that aren't meant to be
treated as nul-terminated strings.  The attribute disables
the checker.  In the future, GCC will also use the attribute to
issue warnings when such arrays are passed to functions that
expect nul-terminated strings.

Attached is a patch to annotate such arrays in Glibc to prevent
warnings on x86_64 (I didn't test any other targets).  The patch
touches the timezone/tzfile.h header even though (IIUC) it comes
from another project.  I'm not familiar with the process for
keeping the timezone directory in sync with tzcode.  Please let
me know how you'd like to go about making this change.

Thanks
Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glibc-nonstring.diff
Type: text/x-patch
Size: 2582 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20171110/a4472078/attachment.bin>


More information about the Libc-alpha mailing list