931c5625a3
The poorly named `strncpy` was originally written to copy data into fixed-sized, disk-resident data structures in an early version of the research Unix kernel. Thus, it has peculiar semantics: it takes source and destination pointer arguments and a length and will *always* modify exactly `length` bytes in the destination buffer. If the length of the source (which is presumed to be a NUL-terminated C-stylestring) is `length` or more chars long, then the result will not be NUL terminated. If it is less than `length` bytes long, then the result will be padded with zeros up to `length`. This is all well and good for storing a file name into a fixed-width directory entry in 6th edition Unix, but it's not useful as a general-purpose string utility. Replaced with calls to strlcpy(), which always properly terminates the destination but doesn't have the additional zeroing behavior. Since the buffers that we're copying into were allocated with malloz(), and thus are guaranteed to be filled with zeros, we're not leaking data, but not double-zeroing either. A few other things were changed. Lengths of destination buffers are now given via `sizeof` instead of manifest constants. One call to `memcpy` took the length from the size of the source argument, thus possibly writing beyond the end of the destination buffer. Changed to a call to strlcpy() with length the sizeof destination. Signed-off-by: Dan Cross <patchdev@fat-dragon.org> |
||
---|---|---|
deps | ||
dist | ||
docs | ||
src | ||
utils | ||
.gitignore | ||
.gitlab-ci.yml | ||
.gitmodules | ||
file_id.diz | ||
GNUmakefile | ||
LICENSE.txt | ||
README.md | ||
setup.sh | ||
STRINGS.CHANGES |
MagickaBBS
A Bulletin Board System for UN*X like platforms.
For documentation, see http://docs.magickabbs.com/