From bd9c787b4f3ec6d539246c24499bdf80c85248cf Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 29 Jul 2021 22:54:47 +0100 Subject: vim-patch:8.1.0802: negative index doesn't work for Blob Problem: Negative index doesn't work for Blob. Solution: Make it work, add a test. (closes vim/vim#3856) https://github.com/vim/vim/commit/a5be9b62480a6f338a72c01e57c9edd0bca8048b Leave tv_blob_get()'s return type untouched. --- src/nvim/eval.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index b7dc00dc08..b16dfad48b 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4647,9 +4647,11 @@ eval_index( tv_blob_set_ret(rettv, blob); } } else { - // The resulting variable is a string of a single - // character. If the index is too big or negative the - // result is empty. + // The resulting variable is a byte value. + // If the index is too big or negative that is an error. + if (n1 < 0) { + n1 = len + n1; + } if (n1 < len && n1 >= 0) { const int v = (int)tv_blob_get(rettv->vval.v_blob, n1); tv_clear(rettv); -- cgit