Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

It's 2015 and Linus still doesn't know what a C string is

Name: Anonymous 2015-05-09 1:49

Name: Anonymous 2015-05-10 21:27

>>16
The problem with strlcpy and friends is they silently truncate the destination string to fit in the provided length. There are many cases where this behavior is not acceptable, and it is often quite trivial to avoid the possibility altogether. In your example, if the caller controls the allocation of buffer there should be no cause to use strlcpy at all - it can just check the length of the source literal first, and allocate a buffer of sufficient size.

strlcpy is a lot like strncpy in the sense that its name encourages programmers to use it in contexts where it is unsuitable. It should really have been given different name (strtrunc, perhaps) to make the intended use more obvious.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List