From: Josh Poimboeuf > Sent: 05 June 2018 16:30 ... > What about just changing it to a memcpy? Seems like that would be > cleaner anyway, since the whole point of strncpy is to add the > terminating NULL, which isn't need here.
Not really, the point of strncpy is to copy strings that might not be '\0' terminated and to zero fill the target buffer. Unfortunately strncpy() has often been used with the assumption that it always terminates the target string - which isn't true. Unfortunately you can't always replace strncpy with strlcpy or snprintf because both those require the source string be '\0' terminated - which isn't a requirement for strncpy. This warning on __builtin_strncpy() seems ott to me. The only fix is to audit the code and replace at least some of the strncpy() with really_strncpy(). David