[Bug c/85902] -Wstringop-truncation false-positive

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu May 24 14:25:00 GMT 2018


Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-05-24
                 CC|                            |msebor at gcc dot gnu.org
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=85619
     Ever confirmed|0                           |1

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning suppression logic looks for an assignment to the destination
immediately after strncpy and when it finds something else it assumes it's a
possible use of the destination.  We discussed (and even briefly experimented
with) enhancing the logic but it's a balancing act between false positives and
false negatives.  We may still come back to this (thus confirmed) but for now,
the best way to avoid the warning is to either nul-terminate the destination or
to decorate it with attribute nonstring to make it clear to GCC that it's not
expected to be nul-terminated.

The documentation problem is being tracked in bug 85619.

More information about the Gcc-bugs mailing list