aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/strings.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/strings.c')
-rw-r--r--src/nvim/strings.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index 5b4f23f30e..b38d4f8a58 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -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);
}