I've seen strncpy(3) being used in the code for copying strings. Ideally, those could be replaced by strlcpy(3bsd), if libbsd can be depended upon on non-BSD systems. Otherwise, memccpy(3) is the second best replacement.
Problems of strncpy(3):
It doesn't guarantee NUL termination (memccpy(3) doesn't either).
It writes the whole remaining of the buffer with '\0's, instead of just 1 '\0'.
In some cases, the writing of the whole buffer with 0s might be actually good, to avoid leaking old values. However, that's better achieved by a separate function call that zeroes the buffer, so I don't think strncpy(3) deserves usage in this project.
Hi,
I've seen strncpy(3) being used in the code for copying strings. Ideally, those could be replaced by strlcpy(3bsd), if libbsd can be depended upon on non-BSD systems. Otherwise, memccpy(3) is the second best replacement.
Problems of strncpy(3):
In some cases, the writing of the whole buffer with 0s might be actually good, to avoid leaking old values. However, that's better achieved by a separate function call that zeroes the buffer, so I don't think
strncpy(3)
deserves usage in this project.What are your thoughts?