diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-07-08 20:11:07 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-07-08 20:11:07 +0200 |
commit | a06ec8f345eabb66e5b7d7c0192cfebdde63115d (patch) | |
tree | c6d2b5213c112e772c1f48b9978909660fe0ada7 /src | |
parent | ba768495c2e6bae74e49d22d489fbf211ecad55e (diff) |
patch 7.4.2002v7.4.2002
Problem: Crash when passing number to filter() or map().
Solution: Convert to a string. (Ozaki Kiichi)
Diffstat (limited to 'src')
-rw-r--r-- | src/eval.c | 6 | ||||
-rw-r--r-- | src/testdir/test_filter_map.vim | 4 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 11 insertions, 1 deletions
diff --git a/src/eval.c b/src/eval.c index 445b6b91c4..a51225d56c 100644 --- a/src/eval.c +++ b/src/eval.c @@ -12044,6 +12044,7 @@ filter_map_one(typval_T *tv, typval_T *expr, int map, int *remp) { typval_T rettv; typval_T argv[3]; + char_u buf[NUMBUFLEN]; char_u *s; int retval = FAIL; int dummy; @@ -12051,9 +12052,9 @@ filter_map_one(typval_T *tv, typval_T *expr, int map, int *remp) copy_tv(tv, &vimvars[VV_VAL].vv_tv); argv[0] = vimvars[VV_KEY].vv_tv; argv[1] = vimvars[VV_VAL].vv_tv; - s = expr->vval.v_string; if (expr->v_type == VAR_FUNC) { + s = expr->vval.v_string; if (call_func(s, (int)STRLEN(s), &rettv, 2, argv, 0L, 0L, &dummy, TRUE, NULL, NULL) == FAIL) goto theend; @@ -12070,6 +12071,9 @@ filter_map_one(typval_T *tv, typval_T *expr, int map, int *remp) } else { + s = get_tv_string_buf_chk(expr, buf); + if (s == NULL) + goto theend; s = skipwhite(s); if (eval1(&s, &rettv, TRUE) == FAIL) goto theend; diff --git a/src/testdir/test_filter_map.vim b/src/testdir/test_filter_map.vim index 6bb063c76d..c8d64ce0a4 100644 --- a/src/testdir/test_filter_map.vim +++ b/src/testdir/test_filter_map.vim @@ -5,10 +5,12 @@ func Test_filter_map_list_expr_string() " filter() call assert_equal([2, 3, 4], filter([1, 2, 3, 4], 'v:val > 1')) call assert_equal([3, 4], filter([1, 2, 3, 4], 'v:key > 1')) + call assert_equal([], filter([1, 2, 3, 4], 0)) " map() call assert_equal([2, 4, 6, 8], map([1, 2, 3, 4], 'v:val * 2')) call assert_equal([0, 2, 4, 6], map([1, 2, 3, 4], 'v:key * 2')) + call assert_equal([9, 9, 9, 9], map([1, 2, 3, 4], 9)) endfunc " dict with expression string @@ -18,10 +20,12 @@ func Test_filter_map_dict_expr_string() " filter() call assert_equal({"bar": 2, "baz": 3}, filter(copy(dict), 'v:val > 1')) call assert_equal({"foo": 1, "baz": 3}, filter(copy(dict), 'v:key > "bar"')) + call assert_equal({}, filter(copy(dict), 0)) " map() call assert_equal({"foo": 2, "bar": 4, "baz": 6}, map(copy(dict), 'v:val * 2')) call assert_equal({"foo": "f", "bar": "b", "baz": "b"}, map(copy(dict), 'v:key[0]')) + call assert_equal({"foo": 9, "bar": 9, "baz": 9}, map(copy(dict), 9)) endfunc " list with funcref diff --git a/src/version.c b/src/version.c index 4dcb286aab..38193e2a31 100644 --- a/src/version.c +++ b/src/version.c @@ -759,6 +759,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2002, +/**/ 2001, /**/ 2000, |