From 59fd0c4132f06a76c460f46ec93fce7b7f1d6f08 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 26 Jan 2017 14:33:03 +0100 Subject: refactor: Remove strncpy/STRNCPY. (#6008) Closes #731 References #851 Note: This does not remove some intentional legacy usages of strncpy. - memcpy isn't equivalent because it doesn't check the string length of `src`, and doesn't zero-out the remainder of `dst`. - xstrlcpy isn't equivalent because it doesn't zero-out the remainder of `dst`. Some Vim logic depends on that (e.g. ex_append which calls vim_strnsave). Helped-by: Douglas Schneider Helped-by: oni-link Helped-by: James McCoy --- src/nvim/path.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 7e1183d5db..374d72ddd3 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -586,7 +586,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, } if (has_mbyte) { len = (size_t)(*mb_ptr2len)(path_end); - STRNCPY(p, path_end, len); + memcpy(p, path_end, len); p += len; path_end += len; } else @@ -2188,7 +2188,8 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf, relative_directory[0] = '/'; relative_directory[1] = NUL; } else { - STRNCPY(relative_directory, fname, p-fname); + assert(p >= fname); + memcpy(relative_directory, fname, (size_t)(p - fname)); relative_directory[p-fname] = NUL; } end_of_path = (char *) (p + 1); -- cgit