diff options
-rw-r--r-- | src/nvim/eval.c | 8 | ||||
-rw-r--r-- | src/nvim/eval/typval.c | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_blob.vim | 7 |
3 files changed, 13 insertions, 4 deletions
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); diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 68fab1dacd..5b416dfa7d 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -2266,7 +2266,7 @@ void tv_blob_copy(typval_T *const from, typval_T *const to) to->vval.v_blob = NULL; } else { tv_blob_alloc_ret(to); - const int len = from->vval.v_blob->bv_ga.ga_len; + int len = from->vval.v_blob->bv_ga.ga_len; if (len > 0) { to->vval.v_blob->bv_ga.ga_data diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim index 568821f564..1faa9af32c 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -95,6 +95,13 @@ func Test_blob_get() call assert_equal(999, get(b, 5, 999)) call assert_equal(-1, get(b, -8)) call assert_equal(999, get(b, -8, 999)) + + call assert_equal(0x00, b[0]) + call assert_equal(0x22, b[2]) + call assert_equal(0x44, b[4]) + call assert_equal(0x44, b[-1]) + call assert_fails('echo b[5]', 'E979:') + call assert_fails('echo b[-8]', 'E979:') endfunc func Test_blob_to_string() |