chibi-scheme
chibi-scheme copied to clipboard
Eliminate uses of strncpy()
Can be replaced with memcpy() or snprintf().
Why?
strncpy()
doesn't guarantee null termination: https://man.openbsd.org/strncpy#EXAMPLES
If you know the length of your strings, you might as well use memcpy()
directly. If you don't know, or don't want to check, snprintf()
is safer, since it takes the buffer size and guarantees null termination.
strlcpy()
is also safe, but it's non-standard.
There's enough space allocated, the 0 byte will be copied. I'd allow a patch to switch everything to memcpy with a manual 0-byte setting, but I don't see the point of snprintf here (you're not checking the return value anyway).