diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-04-20 19:31:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-20 19:31:00 +0800 |
commit | 0ea38c9a53dfcff17703ea22f701ed1cc5bbd7d3 (patch) | |
tree | 60fa7289ee8fc164da54b905d030a09671297867 /src/nvim/mapping.c | |
parent | 4d52b0cf670502caf81b70f2f1e6f8c548b78f58 (diff) | |
download | rneovim-0ea38c9a53dfcff17703ea22f701ed1cc5bbd7d3.tar.gz rneovim-0ea38c9a53dfcff17703ea22f701ed1cc5bbd7d3.tar.bz2 rneovim-0ea38c9a53dfcff17703ea22f701ed1cc5bbd7d3.zip |
refactor: add xmemcpyz() and use it in place of some xstrlcpy() (#28422)
Problem: Using xstrlcpy() when the exact length of the string to be
copied is known is not ideal because it requires adding 1 to
the length and an unnecessary strlen().
Solution: Add xmemcpyz() and use it in place of such xstrlcpy() calls.
Diffstat (limited to 'src/nvim/mapping.c')
-rw-r--r-- | src/nvim/mapping.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 43a4c10ea7..ad02a060a2 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -347,7 +347,7 @@ static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len if (rhs_lua == LUA_NOREF) { mapargs->orig_rhs_len = orig_rhs_len; mapargs->orig_rhs = xcalloc(mapargs->orig_rhs_len + 1, sizeof(char)); - xstrlcpy(mapargs->orig_rhs, orig_rhs, mapargs->orig_rhs_len + 1); + xmemcpyz(mapargs->orig_rhs, orig_rhs, mapargs->orig_rhs_len); if (STRICMP(orig_rhs, "<nop>") == 0) { // "<Nop>" means nothing mapargs->rhs = xcalloc(1, sizeof(char)); // single NUL-char mapargs->rhs_len = 0; @@ -477,7 +477,7 @@ static int str_to_mapargs(const char *strargs, bool is_unmap, MapArguments *mapa return 1; } char lhs_to_replace[256]; - xstrlcpy(lhs_to_replace, to_parse, orig_lhs_len + 1); + xmemcpyz(lhs_to_replace, to_parse, orig_lhs_len); size_t orig_rhs_len = strlen(rhs_start); if (!set_maparg_lhs_rhs(lhs_to_replace, orig_lhs_len, |