This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/88059] Spurious stringop-overflow warning with strlen, malloc and strncpy
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 16 Nov 2018 18:03:39 +0000
- Subject: [Bug middle-end/88059] Spurious stringop-overflow warning with strlen, malloc and strncpy
- Auto-submitted: auto-generated
- References: <bug-88059-4@http.gcc.gnu.org/bugzilla/>
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.