diff options
Diffstat (limited to 'src/nvim/strings.c')
-rw-r--r-- | src/nvim/strings.c | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 37a0fb82da..b38d4f8a58 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -5,7 +5,6 @@ #include "nvim/vim.h" #include "nvim/ascii.h" #include "nvim/strings.h" -#include "nvim/misc2.h" #include "nvim/file_search.h" #include "nvim/buffer.h" #include "nvim/charset.h" @@ -52,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); } @@ -345,24 +343,6 @@ void del_trailing_spaces(char_u *ptr) *q = NUL; } -/* - * Like strcat(), but make sure the result fits in "tosize" bytes and is - * always NUL terminated. - */ -void vim_strcat(char_u *restrict to, const char_u *restrict from, - size_t tosize) - FUNC_ATTR_NONNULL_ALL -{ - size_t tolen = STRLEN(to); - size_t fromlen = STRLEN(from); - - if (tolen + fromlen + 1 > tosize) { - memcpy(to + tolen, from, tosize - tolen - 1); - to[tosize - 1] = NUL; - } else - STRCPY(to + tolen, from); -} - #if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) /* * Compare two strings, ignoring case, using current locale. |