lkml.org 
[lkml]   [2018]   [Jun]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: include/linux/string.h:246:9: warning: '__builtin_strncpy' output truncated before terminating nul copying 4 bytes from a string of the same length
Date
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

\
 
 \ /
  Last update: 2018-06-06 17:34    [W:0.054 / U:14.668 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site