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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning is by design.  Quoting a comment from the code, it "triggers for
LEN arguments that in any meaningful way depend on strlen(SRC)."

The warning in these cases is designed to detect the following anti-pattern:

  strncpy (dest, src, strlen (src));

The code in the test case in comment #0 happens to be safe but calling strncpy
in this instance is not the intended use of the API: when the size of the
destination is known to be sufficient for the copy, the strcpy function is more
appropriate.

It might be possible to avoid the warning for a subset of these safe cases by
trying to also determine whether DEST depends on LEN in the same way as LEN
depends on SRC but in light of the above it doesn't seem worth the effort.

Reply via email to