From 3d6bb8b3fbe21d8a7a4ba975682eb9a4e5170859 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 29 Jul 2021 22:47:33 +0100 Subject: fix(f_remove): partially port v8.2.2779 Fixes remove() copying one extra byte after the end of a Blob's buffer. Can't be fully ported as the change is from blob_remove(), which hasn't been ported yet. --- src/nvim/eval/funcs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index b3afa332f8..660c069e7f 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -7334,7 +7334,7 @@ static void f_remove(typval_T *argvars, typval_T *rettv, FunPtr fptr) memmove(p + idx, p + idx + 1, (size_t)len - idx - 1); b->bv_ga.ga_len--; } else { - // Remove range of items, return list with values. + // Remove range of items, return blob with values. end = (long)tv_get_number_chk(&argvars[2], &error); if (error) { return; @@ -7356,7 +7356,9 @@ static void f_remove(typval_T *argvars, typval_T *rettv, FunPtr fptr) (size_t)(end - idx + 1)); tv_blob_set_ret(rettv, blob); - memmove(p + idx, p + end + 1, (size_t)(len - end)); + if (len - end - 1 > 0) { + memmove(p + idx, p + end + 1, (size_t)(len - end - 1)); + } b->bv_ga.ga_len -= end - idx + 1; } } -- cgit