diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-11-10 08:39:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-10 08:39:21 +0800 |
commit | cd63a9addd6e1114c3524fa041ece560550cfe7b (patch) | |
tree | 846797f471b5de4c230838620ceaeda860de9e17 /src/nvim/eval/userfunc.c | |
parent | ae8ca79920a8d0e928ac1502a10d1d063a06cae5 (diff) | |
download | rneovim-cd63a9addd6e1114c3524fa041ece560550cfe7b.tar.gz rneovim-cd63a9addd6e1114c3524fa041ece560550cfe7b.tar.bz2 rneovim-cd63a9addd6e1114c3524fa041ece560550cfe7b.zip |
refactor: change some xstrndup() and xstrnsave() to xmemdupz() (#25959)
When the given length is exactly the number of bytes to copy, xmemdupz()
makes the intention clearer.
Diffstat (limited to 'src/nvim/eval/userfunc.c')
-rw-r--r-- | src/nvim/eval/userfunc.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 6e7b1e4d67..4b50710649 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1625,7 +1625,7 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t if (fp == NULL) { // Make a copy of the name, if it comes from a funcref variable it could // be changed or deleted in the called function. - name = xstrnsave(funcname, (size_t)len); + name = xmemdupz(funcname, (size_t)len); fname = fname_trans_sid(name, fname_buf, &tofree, &error); } @@ -2089,7 +2089,7 @@ char *save_function_name(char **name, bool skip, int flags, funcdict_T *fudi) if (strncmp(p, "<lambda>", 8) == 0) { p += 8; (void)getdigits(&p, false, 0); - saved = xstrndup(*name, (size_t)(p - *name)); + saved = xmemdupz(*name, (size_t)(p - *name)); if (fudi != NULL) { CLEAR_POINTER(fudi); } @@ -2573,12 +2573,12 @@ void ex_function(exarg_T *eap) if (strncmp(p, "trim", 4) == 0) { // Ignore leading white space. p = skipwhite(p + 4); - heredoc_trimmed = xstrnsave(theline, (size_t)(skipwhite(theline) - theline)); + heredoc_trimmed = xmemdupz(theline, (size_t)(skipwhite(theline) - theline)); } if (*p == NUL) { skip_until = xstrdup("."); } else { - skip_until = xstrnsave(p, (size_t)(skiptowhite(p) - p)); + skip_until = xmemdupz(p, (size_t)(skiptowhite(p) - p)); } do_concat = false; is_heredoc = true; @@ -2598,7 +2598,7 @@ void ex_function(exarg_T *eap) if (strncmp(p, "trim", 4) == 0) { // Ignore leading white space. p = skipwhite(p + 4); - heredoc_trimmed = xstrnsave(theline, (size_t)(skipwhite(theline) - theline)); + heredoc_trimmed = xmemdupz(theline, (size_t)(skipwhite(theline) - theline)); continue; } if (strncmp(p, "eval", 4) == 0) { @@ -2608,7 +2608,7 @@ void ex_function(exarg_T *eap) } break; } - skip_until = xstrnsave(p, (size_t)(skiptowhite(p) - p)); + skip_until = xmemdupz(p, (size_t)(skiptowhite(p) - p)); do_concat = false; is_heredoc = true; } |