To: vim_dev@googlegroups.com Subject: Patch 7.4.2002 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.2002 Problem: Crash when passing number to filter() or map(). Solution: Convert to a string. (Ozaki Kiichi) Files: src/eval.c, src/testdir/test_filter_map.vim *** ../vim-7.4.2001/src/eval.c 2016-07-07 23:04:13.441510589 +0200 --- src/eval.c 2016-07-08 20:02:27.022462486 +0200 *************** *** 12044,12049 **** --- 12044,12050 ---- { typval_T rettv; typval_T argv[3]; + char_u buf[NUMBUFLEN]; char_u *s; int retval = FAIL; int dummy; *************** *** 12051,12059 **** 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) { if (call_func(s, (int)STRLEN(s), &rettv, 2, argv, 0L, 0L, &dummy, TRUE, NULL, NULL) == FAIL) goto theend; --- 12052,12060 ---- copy_tv(tv, &vimvars[VV_VAL].vv_tv); argv[0] = vimvars[VV_KEY].vv_tv; argv[1] = vimvars[VV_VAL].vv_tv; 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,12075 **** --- 12071,12079 ---- } 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; *** ../vim-7.4.2001/src/testdir/test_filter_map.vim 2016-07-04 22:29:22.079959892 +0200 --- src/testdir/test_filter_map.vim 2016-07-08 20:01:07.971609344 +0200 *************** *** 5,14 **** --- 5,16 ---- " 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,27 **** --- 20,31 ---- " 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 *** ../vim-7.4.2001/src/version.c 2016-07-08 15:32:49.945197584 +0200 --- src/version.c 2016-07-08 20:02:10.090708131 +0200 *************** *** 760,761 **** --- 760,763 ---- { /* Add new patch number below this line */ + /**/ + 2002, /**/ -- hundred-and-one symptoms of being an internet addict: 239. You think "surfing" is something you do on dry land. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///