Patch 8.2.0634

7 views
Skip to first unread message

Bram Moolenaar

unread,
Apr 25, 2020, 9:25:29 AM4/25/20
to vim...@googlegroups.com

Patch 8.2.0634
Problem: Crash with null partial and blob.
Solution: Check for NULL pointer. Add more tests. (Yegappan Lakshmanan,
closes #5984)
Files: src/eval.c, src/list.c, src/testdir/test_blob.vim,
src/testdir/test_bufwintabinfo.vim, src/testdir/test_cd.vim,
src/testdir/test_channel.vim, src/testdir/test_cursor_func.vim,
src/testdir/test_eval_stuff.vim, src/testdir/test_expr.vim,
src/testdir/test_filter_map.vim, src/testdir/test_fnamemodify.vim,
src/testdir/test_functions.vim, src/testdir/test_getvar.vim,
src/testdir/test_listdict.vim, src/testdir/test_messages.vim,
src/testdir/test_partial.vim, src/testdir/test_quickfix.vim,
src/testdir/test_tabpage.vim, src/testdir/test_vimscript.vim,
src/testdir/test_window_cmd.vim, src/testdir/test_window_id.vim,
src/testdir/test_writefile.vim


*** ../vim-8.2.0633/src/eval.c 2020-04-24 22:47:26.771359294 +0200
--- src/eval.c 2020-04-25 15:18:14.568117835 +0200
***************
*** 3682,3688 ****
{
if (pt->pt_name != NULL)
return pt->pt_name;
! return pt->pt_func->uf_name;
}

static void
--- 3682,3690 ----
{
if (pt->pt_name != NULL)
return pt->pt_name;
! if (pt->pt_func != NULL)
! return pt->pt_func->uf_name;
! return (char_u *)"";
}

static void
*** ../vim-8.2.0633/src/list.c 2020-04-12 19:37:13.514297270 +0200
--- src/list.c 2020-04-25 15:18:14.568117835 +0200
***************
*** 2167,2172 ****
--- 2167,2175 ----
int val, len;
char_u *p;

+ if (argvars[0].vval.v_blob == NULL)
+ return;
+
len = blob_len(argvars[0].vval.v_blob);
if (argvars[2].v_type != VAR_UNKNOWN)
{
*** ../vim-8.2.0633/src/testdir/test_blob.vim 2020-04-24 22:47:26.771359294 +0200
--- src/testdir/test_blob.vim 2020-04-25 15:18:14.568117835 +0200
***************
*** 33,38 ****
--- 33,39 ----
call assert_fails('let b = 0z.')
call assert_fails('let b = 0z001122.')
call assert_fails('call get("", 1)', 'E896:')
+ call assert_equal(0, len(test_null_blob()))
endfunc

" assignment to a blob
***************
*** 100,105 ****
--- 101,107 ----
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(10, get(test_null_blob(), 2, 10))

call assert_equal(0x00, b[0])
call assert_equal(0x22, b[2])
***************
*** 117,122 ****
--- 119,125 ----
call assert_equal('0z00112233', string(b))
call remove(b, 0, 3)
call assert_equal('0z', string(b))
+ call assert_equal('0z', string(test_null_blob()))
endfunc

func Test_blob_compare()
***************
*** 251,256 ****
--- 254,260 ----
call assert_fails("call remove(b, 3, 2)", 'E979:')
call assert_fails("call remove(1, 0)", 'E896:')
call assert_fails("call remove(b, b)", 'E974:')
+ call assert_fails("call remove(test_null_blob(), 1, 2)", 'E979:')
endfunc

func Test_blob_read_write()
***************
*** 313,318 ****
--- 317,323 ----
call assert_fails('call insert(b, 0, -20)', 'E475:')
call assert_fails('call insert(b, 0, 20)', 'E475:')
call assert_fails('call insert(b, [])', 'E745:')
+ call assert_equal(0, insert(test_null_blob(), 0x33))
endfunc

func Test_blob_reverse()
***************
*** 320,325 ****
--- 325,331 ----
call assert_equal(0zBEADDE, reverse(0zDEADBE))
call assert_equal(0zADDE, reverse(0zDEAD))
call assert_equal(0zDE, reverse(0zDE))
+ call assert_equal(0z, reverse(test_null_blob()))
endfunc

func Test_blob_json_encode()
*** ../vim-8.2.0633/src/testdir/test_bufwintabinfo.vim 2019-12-17 22:40:11.934933029 +0100
--- src/testdir/test_bufwintabinfo.vim 2020-04-25 15:18:14.568117835 +0200
***************
*** 42,47 ****
--- 42,48 ----
sign undefine Mark
enew!
endif
+ call assert_notequal([], getbufinfo(test_null_dict()))

only
let w1_id = win_getid()
*** ../vim-8.2.0633/src/testdir/test_cd.vim 2020-02-11 22:03:43.038846226 +0100
--- src/testdir/test_cd.vim 2020-04-25 15:18:14.568117835 +0200
***************
*** 119,124 ****
--- 119,125 ----
call assert_equal("", d)
" Should not crash
call chdir(d)
+ call assert_equal('', chdir([]))

only | tabonly
call chdir(topdir)
*** ../vim-8.2.0633/src/testdir/test_channel.vim 2020-04-24 22:47:26.771359294 +0200
--- src/testdir/test_channel.vim 2020-04-25 15:18:14.568117835 +0200
***************
*** 1139,1144 ****
--- 1139,1146 ----
call assert_equal("run", job_status(job))
call assert_equal('channel fail', string(job_getchannel(job)))
call assert_equal('fail', ch_status(job))
+ call assert_equal('no process', string(test_null_job()))
+ call assert_equal('channel fail', string(test_null_channel()))
call job_stop(job)
endfunc

***************
*** 1706,1711 ****
--- 1708,1714 ----
let d.a = function('string', [d])
try
let d.b = ch_open('nowhere:123', {'close_cb': d.a})
+ call test_garbagecollect_now()
catch
call assert_exception('E901:')
endtry
***************
*** 1893,1898 ****
--- 1896,1902 ----
endif
let g:Ch_close_ret = ''
call ch_setoptions(handle, {'close_cb': {ch -> execute("let g:Ch_close_ret = 'closed'")}})
+ call test_garbagecollect_now()

call assert_equal('', ch_evalexpr(handle, 'close me'))
call WaitForAssert({-> assert_equal('closed', g:Ch_close_ret)})
*** ../vim-8.2.0633/src/testdir/test_cursor_func.vim 2020-04-20 16:49:56.701830076 +0200
--- src/testdir/test_cursor_func.vim 2020-04-25 15:18:14.568117835 +0200
***************
*** 2,7 ****
--- 2,8 ----

func Test_wrong_arguments()
call assert_fails('call cursor(1. 3)', 'E474:')
+ call assert_fails('call cursor(test_null_list())', 'E474:')
endfunc

func Test_move_cursor()
*** ../vim-8.2.0633/src/testdir/test_eval_stuff.vim 2020-04-24 22:47:26.771359294 +0200
--- src/testdir/test_eval_stuff.vim 2020-04-25 15:18:14.568117835 +0200
***************
*** 41,46 ****
--- 41,49 ----
call assert_fails('call mkdir("Xfile", "p")', 'E739')
call delete('Xfile')
call delete('Xmkdir', 'rf')
+ call assert_equal(0, mkdir(test_null_string()))
+ call assert_fails('call mkdir([])', 'E730')
+ call assert_fails('call mkdir("abc", [], [])', 'E745')
endfunc

func Test_line_continuation()
***************
*** 223,228 ****
--- 226,232 ----
call assert_fails('execute test_null_blob()', 'E976:')
execute test_null_string()
call assert_fails('execute test_null_partial()', 'E729:')
+ call assert_fails('execute test_unknown()', 'E908:')
if has('job')
call assert_fails('execute test_null_job()', 'E908:')
call assert_fails('execute test_null_channel()', 'E908:')
*** ../vim-8.2.0633/src/testdir/test_expr.vim 2020-04-24 22:47:26.775359283 +0200
--- src/testdir/test_expr.vim 2020-04-25 15:18:14.568117835 +0200
***************
*** 24,29 ****
--- 24,30 ----
call assert_fails('echo base.method > instance.method')
call assert_equal(0, test_null_function() == function('min'))
call assert_equal(1, test_null_function() == test_null_function())
+ call assert_fails('eval 10 == test_unknown()', 'E685:')
endfunc

func Test_version()
***************
*** 100,106 ****
endfor
endfunc

! func Test_set_reg_null_list()
call setreg('x', test_null_list())
endfunc

--- 101,107 ----
endfor
endfunc

! func Test_setreg_null_list()
call setreg('x', test_null_list())
endfunc

*** ../vim-8.2.0633/src/testdir/test_filter_map.vim 2020-04-24 22:47:26.775359283 +0200
--- src/testdir/test_filter_map.vim 2020-04-25 15:18:14.568117835 +0200
***************
*** 97,102 ****
--- 97,104 ----
call assert_fails("let l = filter([1, 2, 3], '{}')", 'E728:')
call assert_fails("let l = filter({'k' : 10}, '{}')", 'E728:')
call assert_fails("let l = filter([1, 2], {})", 'E731:')
+ call assert_equal(0, filter(test_null_list(), 0))
+ call assert_equal(0, filter(test_null_dict(), 0))
call assert_equal(0, map(test_null_list(), '"> " .. v:val'))
call assert_equal(0, map(test_null_dict(), '"> " .. v:val'))
call assert_equal([1, 2, 3], filter([1, 2, 3], test_null_function()))
*** ../vim-8.2.0633/src/testdir/test_fnamemodify.vim 2020-02-05 21:13:57.296873717 +0100
--- src/testdir/test_fnamemodify.vim 2020-04-25 15:18:14.568117835 +0200
***************
*** 86,89 ****
--- 86,93 ----
" :e never includes the whole filename, so "a.b":e:e:e --> "b"
call assert_equal('b.c', fnamemodify('a.b.c.d.e', ':r:r:e:e:e'))
call assert_equal('b.c', fnamemodify('a.b.c.d.e', ':r:r:e:e:e:e'))
+
+ call assert_equal('', fnamemodify(test_null_string(), test_null_string()))
endfunc
+
+ " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.0633/src/testdir/test_functions.vim 2020-04-24 22:47:26.775359283 +0200
--- src/testdir/test_functions.vim 2020-04-25 15:18:14.572117828 +0200
***************
*** 480,485 ****
--- 480,486 ----
call assert_equal('~.f/bar', pathshorten('~.foo/bar'))
call assert_equal('.~f/bar', pathshorten('.~foo/bar'))
call assert_equal('~/f/bar', pathshorten('~/foo/bar'))
+ call assert_fails('call pathshorten([])', 'E730:')
endfunc

func Test_strpart()
***************
*** 970,975 ****
--- 971,977 ----
call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8))
call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing'))
call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img'))
+ call assert_equal(['', -1, -1], matchstrpos(test_null_list(), '\a'))
endfunc

func Test_nextnonblank_prevnonblank()
***************
*** 1222,1227 ****
--- 1224,1230 ----
syntax off
endfunc

+ " Test for the col() function
func Test_col()
new
call setline(1, 'abcdef')
***************
*** 1332,1337 ****
--- 1335,1341 ----
call assert_equal(-2, c)

call assert_fails('call inputlist("")', 'E686:')
+ call assert_fails('call inputlist(test_null_list())', 'E686:')
endfunc

func Test_balloon_show()
***************
*** 2227,2232 ****
--- 2231,2246 ----
call delete('XTest_echoraw')
endfunc

+ " Test for echo highlighting
+ func Test_echohl()
+ echohl Search
+ echo 'Vim'
+ call assert_equal('Vim', Screenline(&lines))
+ " TODO: How to check the highlight group used by echohl?
+ " ScreenAttrs() returns all zeros.
+ echohl None
+ endfunc
+
" Test for the eval() function
func Test_eval()
call assert_fails("call eval('5 a')", 'E488:')
***************
*** 2258,2264 ****
--- 2272,2298 ----
call setpos('.', sp)
normal jyl
call assert_equal('6', @")
+ call assert_equal(-1, setpos('.', test_null_list()))
+ call assert_equal(-1, setpos('.', {}))
close!
endfunc

+ " Test for glob()
+ func Test_glob()
+ call assert_equal('', glob(test_null_string()))
+ call assert_equal('', globpath(test_null_string(), test_null_string()))
+ endfunc
+
+ " Test for browse()
+ func Test_browse()
+ CheckFeature browse
+ call assert_fails('call browse([], "open", "x", "a.c")', 'E745:')
+ endfunc
+
+ " Test for browsedir()
+ func Test_browsedir()
+ CheckFeature browse
+ call assert_fails('call browsedir("open", [])', 'E730:')
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.0633/src/testdir/test_getvar.vim 2020-01-14 19:05:34.049710485 +0100
--- src/testdir/test_getvar.vim 2020-04-25 15:18:14.572117828 +0200
***************
*** 142,147 ****
--- 142,152 ----
call assert_equal({'func has': 'no dict'}, get(l:F, 'dict', {'func has': 'no dict'}))
call assert_equal(0, get(l:F, 'dict'))
call assert_equal([], get(l:F, 'args'))
+ let NF = test_null_function()
+ call assert_equal('', get(NF, 'name'))
+ call assert_equal(NF, get(NF, 'func'))
+ call assert_equal(0, get(NF, 'dict'))
+ call assert_equal([], get(NF, 'args'))
endfunc

" get({partial}, {what} [, {default}]) - in test_partial.vim
*** ../vim-8.2.0633/src/testdir/test_listdict.vim 2020-04-24 22:47:26.775359283 +0200
--- src/testdir/test_listdict.vim 2020-04-25 15:18:14.572117828 +0200
***************
*** 724,729 ****
--- 724,730 ----
call assert_true(dict4 == dict4copy)
endfunc

+ " Test for extending lists and dictionaries
func Test_listdict_extend()
" Test extend() with lists

***************
*** 926,931 ****
--- 927,934 ----
call assert_fails("let l[1.1] = 4", 'E806:')
call assert_fails("let l[:i] = [4, 5]", 'E121:')
call assert_fails("let l[:3.2] = [4, 5]", 'E806:')
+ let t = test_unknown()
+ call assert_fails("echo t[0]", 'E685:')
endfunc

" Test for a null list
***************
*** 943,949 ****
call assert_equal(0, uniq(l))
call assert_fails("let k = [] + l", 'E15:')
call assert_fails("let k = l + []", 'E15:')
! call assert_equal(0, len(copy(test_null_list())))
endfunc

" Test for a null dict
--- 946,968 ----
call assert_equal(0, uniq(l))
call assert_fails("let k = [] + l", 'E15:')
call assert_fails("let k = l + []", 'E15:')
! call assert_equal(0, len(copy(l)))
! call assert_equal(0, count(l, 5))
! call assert_equal([], deepcopy(l))
! call assert_equal(5, get(l, 2, 5))
! call assert_equal(-1, index(l, 2, 5))
! call assert_equal(0, insert(l, 2, -1))
! call assert_equal(0, min(l))
! call assert_equal(0, max(l))
! call assert_equal(0, remove(l, 0, 2))
! call assert_equal([], repeat(l, 2))
! call assert_equal(0, reverse(l))
! call assert_equal(0, sort(l))
! call assert_equal('[]', string(l))
! call assert_equal(0, extend(l, l, 0))
! lockvar l
! call assert_equal(1, islocked('l'))
! unlockvar l
endfunc

" Test for a null dict
***************
*** 958,966 ****
call assert_equal(0, values(d))
call assert_false(has_key(d, 'k'))
call assert_equal('{}', string(d))
! call assert_fails('let x = test_null_dict()[10]')
call assert_equal({}, {})
! call assert_equal(0, len(copy(test_null_dict())))
endfunc

" vim: shiftwidth=2 sts=2 expandtab
--- 977,996 ----
call assert_equal(0, values(d))
call assert_false(has_key(d, 'k'))
call assert_equal('{}', string(d))
! call assert_fails('let x = d[10]')
call assert_equal({}, {})
! call assert_equal(0, len(copy(d)))
! call assert_equal(0, count(d, 'k'))
! call assert_equal({}, deepcopy(d))
! call assert_equal(20, get(d, 'k', 20))
! call assert_equal(0, min(d))
! call assert_equal(0, max(d))
! call assert_equal(0, remove(d, 'k'))
! call assert_equal('{}', string(d))
! call assert_equal(0, extend(d, d, 0))
! lockvar d
! call assert_equal(1, islocked('d'))
! unlockvar d
endfunc

" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.0633/src/testdir/test_messages.vim 2020-04-22 19:13:16.047410502 +0200
--- src/testdir/test_messages.vim 2020-04-25 15:18:14.572117828 +0200
***************
*** 305,313 ****
--- 305,316 ----
echom test_null_dict()
echom test_null_blob()
echom test_null_string()
+ echom test_null_function()
echom test_null_partial()
if has('job')
echom test_null_job()
echom test_null_channel()
endif
endfunc
+
+ " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.0633/src/testdir/test_partial.vim 2020-04-24 22:47:26.775359283 +0200
--- src/testdir/test_partial.vim 2020-04-25 15:18:14.572117828 +0200
***************
*** 194,199 ****
--- 194,201 ----
call assert_equal("function('MyFunc', {'one': 1})", string(F))
let F = function('MyFunc', ['foo'], d)
call assert_equal("function('MyFunc', ['foo'], {'one': 1})", string(F))
+ call assert_equal("function('')", string(test_null_function()))
+ call assert_equal("function('')", string(test_null_partial()))
endfunc

func Test_func_unref()
*** ../vim-8.2.0633/src/testdir/test_quickfix.vim 2020-03-14 17:21:30.667427405 +0100
--- src/testdir/test_quickfix.vim 2020-04-25 15:18:14.572117828 +0200
***************
*** 2158,2163 ****
--- 2158,2175 ----
call g:Xsetlist([], 'a', {'context':246})
let d = g:Xgetlist({'context':1})
call assert_equal(246, d.context)
+ " set other Vim data types as context
+ call g:Xsetlist([], 'a', {'context' : test_null_blob()})
+ if has('channel')
+ call g:Xsetlist([], 'a', {'context' : test_null_channel()})
+ endif
+ if has('job')
+ call g:Xsetlist([], 'a', {'context' : test_null_job()})
+ endif
+ call g:Xsetlist([], 'a', {'context' : test_null_function()})
+ call g:Xsetlist([], 'a', {'context' : test_null_partial()})
+ call g:Xsetlist([], 'a', {'context' : ''})
+ call test_garbagecollect_now()
if a:cchar == 'l'
" Test for copying context across two different location lists
new | only
*** ../vim-8.2.0633/src/testdir/test_tabpage.vim 2020-02-17 21:33:26.270098788 +0100
--- src/testdir/test_tabpage.vim 2020-04-25 15:18:14.572117828 +0200
***************
*** 130,135 ****
--- 130,137 ----
1tabmove
call assert_equal(2, tabpagenr())

+ call assert_fails('let t = tabpagenr("#")', 'E15:')
+ call assert_equal(0, tabpagewinnr(-1))
call assert_fails("99tabmove", 'E16:')
call assert_fails("+99tabmove", 'E16:')
call assert_fails("-99tabmove", 'E16:')
*** ../vim-8.2.0633/src/testdir/test_vimscript.vim 2020-04-23 13:37:59.498978692 +0200
--- src/testdir/test_vimscript.vim 2020-04-25 15:18:14.572117828 +0200
***************
*** 1164,1169 ****
--- 1164,1181 ----
call assert_equal(v:t_bool, type(v:true))
call assert_equal(v:t_none, type(v:none))
call assert_equal(v:t_none, type(v:null))
+ call assert_equal(v:t_string, type(test_null_string()))
+ call assert_equal(v:t_func, type(test_null_function()))
+ call assert_equal(v:t_func, type(test_null_partial()))
+ call assert_equal(v:t_list, type(test_null_list()))
+ call assert_equal(v:t_dict, type(test_null_dict()))
+ if has('job')
+ call assert_equal(v:t_job, type(test_null_job()))
+ endif
+ if has('channel')
+ call assert_equal(v:t_channel, type(test_null_channel()))
+ endif
+ call assert_equal(v:t_blob, type(test_null_blob()))

call assert_fails("call type(test_void())", 'E685:')
call assert_fails("call type(test_unknown())", 'E685:')
*** ../vim-8.2.0633/src/version.c 2020-04-24 22:47:26.775359283 +0200
--- src/version.c 2020-04-25 15:19:48.047939571 +0200
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 634,
/**/

--
hundred-and-one symptoms of being an internet addict:
12. You turn off your Wifi and get this awful empty feeling, like you just
pulled the plug on a loved one.

/// Bram Moolenaar -- Br...@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 ///
Reply all
Reply to author
Forward
0 new messages