0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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 #3856)
This commit is contained in:
Bram Moolenaar
2019-01-24 12:31:44 +01:00
parent fb1199d934
commit a5be9b6248
5 changed files with 20 additions and 6 deletions

View File

@@ -4723,12 +4723,13 @@ eval_index(
}
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)
{
int v = (int)blob_get(rettv->vval.v_blob, n1);
int v = blob_get(rettv->vval.v_blob, n1);
clear_tv(rettv);
rettv->v_type = VAR_NUMBER;