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

--- Comment #3 from Allison Karlitskaya <allison.karlitskaya at redhat dot com> 
---
(In reply to Martin Sebor from comment #2)
> Thanks for the report (and for getting Glibc to update its headers).  The
> problem with strncpy is that its correct and intended uses (filling a buffer
> without necessarily nul-terminating it) are indistinguishable from the
> misuses (attempting to create a possibly truncated string as a copy of
> another).
> 
> Since there are more misuses than the correct uses of the function, the
> warning relies on authors of the correct code to annotate it with attribute
> nonstring.  This is mentioned in the documentation of the warning.  The
> warning itself doesn't mention this because the right solution is likely to
> fix the copy.
> 
> I realize this approach makes the minority of authors of correct/safe code
> pay the price for the mistakes of the majority of others and so must be
> frustrating if you're in the first group.  Sorry.  The opposite approach
> obviously wouldn't be effective.
> 
> If it helps, here's an article I wrote on this topic when the warning was
> first added:
> https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-
> with-gcc-8

hi Martin,

Thanks for the reply.  I agree with everything you've written, and I wouldn't
want to change the behaviour here.  The only thing I'm asking is that a brief
mention about "consider the nonstring attribute" be added to the warning text.

Reply via email to