comparison src/eval.c @ 15589:44ea60ca593b v8.1.0802

patch 8.1.0802: negative index doesn't work for Blob commit https://github.com/vim/vim/commit/a5be9b62480a6f338a72c01e57c9edd0bca8048b Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 24 12:31:44 2019 +0100 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 https://github.com/vim/vim/issues/3856)
author Bram Moolenaar <Bram@vim.org>
date Thu, 24 Jan 2019 12:45:05 +0100
parents c2382f0d1279
children e26caeb30026
comparison
equal deleted inserted replaced
15588:d1b7f02e6d29 15589:44ea60ca593b
4721 } 4721 }
4722 } 4722 }
4723 } 4723 }
4724 else 4724 else
4725 { 4725 {
4726 // The resulting variable is a string of a single 4726 // The resulting variable is a byte value.
4727 // character. If the index is too big or negative the 4727 // If the index is too big or negative that is an error.
4728 // result is empty. 4728 if (n1 < 0)
4729 n1 = len + n1;
4729 if (n1 < len && n1 >= 0) 4730 if (n1 < len && n1 >= 0)
4730 { 4731 {
4731 int v = (int)blob_get(rettv->vval.v_blob, n1); 4732 int v = blob_get(rettv->vval.v_blob, n1);
4732 4733
4733 clear_tv(rettv); 4734 clear_tv(rettv);
4734 rettv->v_type = VAR_NUMBER; 4735 rettv->v_type = VAR_NUMBER;
4735 rettv->vval.v_number = v; 4736 rettv->vval.v_number = v;
4736 } 4737 }