https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87028
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic CC| |msebor at gcc dot gnu.org --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- This is the same issue as pr84474. The warning in all these cases is by design. There is an (undocumented) suppression mechanism in GCC to avoid warning for instances of calls that are followed by the nul assignment. The suppression works in the second example when GCC sees the nul assignment but not in the first or last one where the warning triggers before access to the subsequent statement is available. In both of these, the strncpy call is transformed early on to memcpy (the warning is issued just before this transformation) so avoiding the diagnostic in these cases would prevent diagnosing instances where the nul isn't stored next. In effect, it's a tradeoff between false positives and false negatives, forced by the early transformation. IMO, the early folding of strncpy to memcpy is unhelpful (it causes false negatives in buffer overflow detection) and should be done later, but so far I haven't been successful at convincing others to defer it.