diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2020-11-25 17:27:39 +0000 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2021-09-15 21:54:00 +0100 |
commit | c1b8731ece81cdbc43fbb6050eaf12e84abdc4b0 (patch) | |
tree | ff537217a607c7acf930b6913d531750dcafbb51 /src/nvim/eval/funcs.c | |
parent | d346ac536fbb7716e6a0d0f5ca7af9c39ec95de0 (diff) | |
download | rneovim-c1b8731ece81cdbc43fbb6050eaf12e84abdc4b0.tar.gz rneovim-c1b8731ece81cdbc43fbb6050eaf12e84abdc4b0.tar.bz2 rneovim-c1b8731ece81cdbc43fbb6050eaf12e84abdc4b0.zip |
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
Diffstat (limited to 'src/nvim/eval/funcs.c')
-rw-r--r-- | src/nvim/eval/funcs.c | 10 |
1 files changed, 7 insertions, 3 deletions
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) { |