mirror of
https://github.com/neovim/neovim.git
synced 2025-09-12 06:18:16 +00:00
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 <ds3@ualberta.ca> Helped-by: oni-link <knil.ino@gmail.com> Helped-by: James McCoy <jamessan@jamessan.com>
This commit is contained in:
@@ -51,15 +51,14 @@ char_u *vim_strsave(const char_u *string)
|
||||
return (char_u *)xstrdup((char *)string);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy up to "len" bytes of "string" into newly allocated memory and
|
||||
* terminate with a NUL.
|
||||
* The allocated memory always has size "len + 1", also when "string" is
|
||||
* shorter.
|
||||
*/
|
||||
/// Copy up to `len` bytes of `string` into newly allocated memory and
|
||||
/// terminate with a NUL. The allocated memory always has size `len + 1`, even
|
||||
/// when `string` is shorter.
|
||||
char_u *vim_strnsave(const char_u *string, size_t len)
|
||||
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
// strncpy is intentional: some parts of Vim use `string` shorter than `len`
|
||||
// and expect the remainder to be zeroed out.
|
||||
return (char_u *)strncpy(xmallocz(len), (char *)string, len);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user