[PATCH] warn for strlen of arrays with missing nul (PR 86552)

Martin Sebor msebor@gmail.com
Thu Jul 19 20:09:00 GMT 2018


In the discussion of my patch for pr86532 Bernd noted that
GCC silently accepts constant character arrays with no
terminating nul as arguments to strlen (and other string
functions).

The attached patch is a first step in detecting these kinds
of bugs in strlen calls by issuing -Wstringop-overflow.
The next step is to modify all other handlers of built-in
functions to detect the same problem (not part of this patch).
Yet another step is to detect these problems in arguments
initialized using the non-string form:

   const char a[] = { 'a', 'b', 'c' };

This patch is meant to apply on top of the one for bug 86532
(I tested it with an earlier version of that patch so there
is code in the context that does not appear in the latest
version of the other diff).

Martin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-86552.diff
Type: text/x-patch
Size: 19657 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20180719/6d6f5571/attachment.bin>


More information about the Gcc-patches mailing list