* [PATCH] enhance documentation of -Wstringop-truncation
@ 2017-12-03 23:55 Martin Sebor
2017-12-05 16:57 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Martin Sebor @ 2017-12-03 23:55 UTC (permalink / raw)
To: Gcc Patch List
[-- Attachment #1: Type: text/plain, Size: 505 bytes --]
It was suggested to me that it might be helpful to mention
attribute nonstring as a solution to -Wstringop-truncation
warnings. I think it's a good idea to add a reference to
the attribute to the manual. The attached patch does that.
Since the attribute is suitable only under rare conditions
suggesting it in the text of the diagnostics (e.g., in the
form of a note) would unlikely be useful (and, if acted on,
could even lead to other kinds of warnings) so I opted not
to make such a change.
Martin
[-- Attachment #2: wstringop-trunc-nonstring.diff --]
[-- Type: text/x-patch, Size: 990 bytes --]
2017-12-03 Martin Sebor <msebor@redhat.com>
* doc/invoke.texi (-Wstringop-truncation): Mention attribute nonstring.
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi (revision 255369)
+++ gcc/doc/invoke.texi (working copy)
@@ -5256,6 +5256,14 @@ void copy (const char *s)
@}
@end smallexample
+In situations where a character array is intended to store a sequence
+of bytes with no terminating @code{NUL} such an array may be annotated
+with attribute @code{nonstring} to avoid this warning. Such arrays,
+however, are not suitable arguments to functions that expect
+@code{NUL}-terminated strings. To help detect accidental misuses of
+such arrays, GCC issues warnings unless it can prove that the use is
+safe. @xref{Common Variable Attributes}.
+
@item -Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{|}cold@r{|}malloc@r{]}
@opindex Wsuggest-attribute=
@opindex Wno-suggest-attribute=
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] enhance documentation of -Wstringop-truncation
2017-12-03 23:55 [PATCH] enhance documentation of -Wstringop-truncation Martin Sebor
@ 2017-12-05 16:57 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2017-12-05 16:57 UTC (permalink / raw)
To: Martin Sebor, Gcc Patch List
On 12/03/2017 04:55 PM, Martin Sebor wrote:
> It was suggested to me that it might be helpful to mention
> attribute nonstring as a solution to -Wstringop-truncation
> warnings.  I think it's a good idea to add a reference to
> the attribute to the manual.  The attached patch does that.
>
> Since the attribute is suitable only under rare conditions
> suggesting it in the text of the diagnostics (e.g., in the
> form of a note) would unlikely be useful (and, if acted on,
> could even lead to other kinds of warnings) so I opted not
> to make such a change.
>
> Martin
>
> wstringop-trunc-nonstring.diff
>
>
> 2017-12-03 Martin Sebor <msebor@redhat.com>
>
> * doc/invoke.texi (-Wstringop-truncation): Mention attribute nonstring.
OK.
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-12-05 16:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-03 23:55 [PATCH] enhance documentation of -Wstringop-truncation Martin Sebor
2017-12-05 16:57 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).