fix(f_insert): partially port v8.2.0634

Fixes a crash in f_insert() when inserting into a NULL blob.
Include blob-related test changes and some other simple changes.
This commit is contained in:
Sean Dewar 2021-07-29 22:32:22 +01:00
parent 9b5c9dbfa7
commit 19232593ba
No known key found for this signature in database
GPG Key ID: 08CC2C83AD41B581
5 changed files with 21 additions and 0 deletions

View File

@ -4984,6 +4984,10 @@ static void f_insert(typval_T *argvars, typval_T *rettv, FunPtr fptr)
bool error = false;
if (argvars[0].v_type == VAR_BLOB) {
if (argvars[0].vval.v_blob == NULL) {
return;
}
long before = 0;
const int len = tv_blob_len(argvars[0].vval.v_blob);

View File

@ -33,6 +33,7 @@ func Test_blob_create()
call assert_fails('let b = 0z.')
call assert_fails('let b = 0z001122.')
call assert_fails('call get("", 1)', 'E896:')
call assert_equal(0, len(v:_null_blob))
endfunc
" assignment to a blob
@ -99,6 +100,7 @@ func Test_blob_get()
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(v:_null_blob, 2, 10))
call assert_equal(0x00, b[0])
call assert_equal(0x22, b[2])
@ -248,6 +250,7 @@ func Test_blob_func_remove()
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(v:_null_blob, 1, 2)", 'E979:')
endfunc
func Test_blob_read_write()
@ -304,6 +307,7 @@ func Test_blob_insert()
call assert_fails('call insert(b, -1)', 'E475:')
call assert_fails('call insert(b, 257)', 'E475:')
call assert_fails('call insert(b, 0, [9])', 'E745:')
call assert_equal(0, insert(v:_null_blob, 0x33))
endfunc
func Test_blob_reverse()
@ -311,6 +315,7 @@ func Test_blob_reverse()
call assert_equal(0zBEADDE, reverse(0zDEADBE))
call assert_equal(0zADDE, reverse(0zDEAD))
call assert_equal(0zDE, reverse(0zDE))
call assert_equal(0z, reverse(v:_null_blob))
endfunc
func Test_blob_lock()

View File

@ -72,4 +72,8 @@ func Test_fnamemodify_er()
" :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(v:_null_string, v:_null_string))
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -2221,6 +2221,10 @@ func Xproperty_tests(cchar)
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' : v:_null_blob})
call g:Xsetlist([], 'a', {'context' : ''})
call test_garbagecollect_now()
if a:cchar == 'l'
" Test for copying context across two different location lists
new | only

View File

@ -1152,6 +1152,10 @@ func Test_type()
call assert_equal(v:t_float, type(0.0))
call assert_equal(v:t_bool, type(v:false))
call assert_equal(v:t_bool, type(v:true))
call assert_equal(v:t_string, type(v:_null_string))
call assert_equal(v:t_list, type(v:_null_list))
call assert_equal(v:t_dict, type(v:_null_dict))
call assert_equal(v:t_blob, type(v:_null_blob))
endfunc
"-------------------------------------------------------------------------------