From c1b8731ece81cdbc43fbb6050eaf12e84abdc4b0 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Wed, 25 Nov 2020 17:27:39 +0000 Subject: vim-patch:8.1.0755: error message for get() on a Blob with invalid index Problem: Error message for get() on a Blob with invalid index. Solution: Return an empty Blob, like get() on a List does. https://github.com/vim/vim/commit/2ea773b468a1143214c2f12b91ab5e1e7abb4a14 --- src/nvim/eval/funcs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 3c25d76866..e804029187 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2809,14 +2809,18 @@ static void f_get(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (argvars[0].v_type == VAR_BLOB) { bool error = false; - const int idx = tv_get_number_chk(&argvars[1], &error); + int idx = tv_get_number_chk(&argvars[1], &error); if (!error) { rettv->v_type = VAR_NUMBER; - if (idx >= tv_blob_len(argvars[0].vval.v_blob)) { - EMSGN(_(e_blobidx), idx); + if (idx < 0) { + idx = tv_blob_len(argvars[0].vval.v_blob) + idx; + } + if (idx < 0 || idx >= tv_blob_len(argvars[0].vval.v_blob)) { + rettv->vval.v_number = -1; } else { rettv->vval.v_number = tv_blob_get(argvars[0].vval.v_blob, idx); + tv = rettv; } } } else if (argvars[0].v_type == VAR_LIST) { -- cgit