https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96951
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Severity|normal |enhancement Ever confirmed|0 |1 Last reconfirmed| |2020-09-07 Blocks| |88781 --- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> --- The warning suppression only considers an explicit nul assignment, not a test for one. If in the code the test case was derived from the string member is not necessarily meant to be a string then declaring it with attribute nonstring avoids the warning: struct buffer { __attribute__((nonstring)) char string[10]; }; The attribute will trigger other warnings in uses of the member that aren't clearly nul-terminated. There are different ways to write the code to avoid the warning and I'm not sure that any one of them is necessarily the best. I'd rather users read up on the problem with strncpy (and strncat) and choose what works best for them. I wrote a blog post about this some time ago: https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/ As for memccpy, doesn't know about it yet but it's on my to-do list to add it to resolve pr88814. Ideally, I'd also like to improve Glibc's memccpy to make it one-pass unless someone beats me to it (hint, hint ;-) Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88781 [Bug 88781] [meta-bug] bogus/missing -Wstringop-truncation warnings