0
0
mirror of https://github.com/vim/vim.git synced 2025-09-28 04:24:06 -04:00

patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer

Problem:    Errors when calling prop_remove() for an unloaded buffer.
Solution:   Bail out when the buffer is not loaded.  Add a few more tests for
            failing when the buffer number is invalid.
This commit is contained in:
Bram Moolenaar
2019-05-24 21:22:29 +02:00
parent d79eef2eb1
commit f0884c5f3f
3 changed files with 30 additions and 11 deletions

View File

@@ -69,6 +69,8 @@ func Test_proptype_buf()
call assert_equal(1, len(prop_type_list({'bufnr': bufnr}))) call assert_equal(1, len(prop_type_list({'bufnr': bufnr})))
call prop_type_delete('two', {'bufnr': bufnr}) call prop_type_delete('two', {'bufnr': bufnr})
call assert_equal(0, len(prop_type_list({'bufnr': bufnr}))) call assert_equal(0, len(prop_type_list({'bufnr': bufnr})))
call assert_fails("call prop_type_add('one', {'bufnr': 98764})", "E158:")
endfunc endfunc
func AddPropTypes() func AddPropTypes()
@@ -124,6 +126,8 @@ func Test_prop_add()
let expected = [{'col': 5, 'length': 0, 'type': 'two', 'id': 0, 'start': 1, 'end': 1}] let expected = [{'col': 5, 'length': 0, 'type': 'two', 'id': 0, 'start': 1, 'end': 1}]
call assert_equal(expected, prop_list(1)) call assert_equal(expected, prop_list(1))
call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:')
call DeletePropTypes() call DeletePropTypes()
bwipe! bwipe!
endfunc endfunc
@@ -136,15 +140,18 @@ func Test_prop_remove()
call assert_equal(props, prop_list(1)) call assert_equal(props, prop_list(1))
" remove by id " remove by id
call prop_remove({'id': 12}, 1) call assert_equal(1, prop_remove({'id': 12}, 1))
unlet props[2] unlet props[2]
call assert_equal(props, prop_list(1)) call assert_equal(props, prop_list(1))
" remove by type " remove by type
call prop_remove({'type': 'one'}, 1) call assert_equal(1, prop_remove({'type': 'one'}, 1))
unlet props[1] unlet props[1]
call assert_equal(props, prop_list(1)) call assert_equal(props, prop_list(1))
" remove from unknown buffer
call assert_fails("call prop_remove({'type': 'one', 'bufnr': 123456}, 1)", 'E158:')
call DeletePropTypes() call DeletePropTypes()
bwipe! bwipe!
endfunc endfunc
@@ -760,3 +767,16 @@ func Test_textprop_empty_buffer()
call prop_add(1, 1, {'type': 'comment'}) call prop_add(1, 1, {'type': 'comment'})
close close
endfunc endfunc
func Test_textprop_remove_from_buf()
new
let buf = bufnr('')
call prop_type_add('one', {'bufnr': buf})
call prop_add(1, 1, {'type': 'one', 'id': 234})
file x
edit y
call prop_remove({'id': 234, 'bufnr': buf}, 1)
call prop_type_delete('one', {'bufnr': buf})
bwipe! x
close
endfunc

View File

@@ -129,7 +129,7 @@ get_bufnr_from_arg(typval_T *arg, buf_T **buf)
di = dict_find(arg->vval.v_dict, (char_u *)"bufnr", -1); di = dict_find(arg->vval.v_dict, (char_u *)"bufnr", -1);
if (di != NULL) if (di != NULL)
{ {
*buf = tv_get_buf(&di->di_tv, FALSE); *buf = get_buf_arg(&di->di_tv);
if (*buf == NULL) if (*buf == NULL)
return FAIL; return FAIL;
} }
@@ -560,13 +560,10 @@ f_prop_remove(typval_T *argvars, typval_T *rettv)
} }
dict = argvars[0].vval.v_dict; dict = argvars[0].vval.v_dict;
di = dict_find(dict, (char_u *)"bufnr", -1); if (get_bufnr_from_arg(&argvars[0], &buf) == FAIL)
if (di != NULL) return;
{ if (buf->b_ml.ml_mfp == NULL)
buf = tv_get_buf(&di->di_tv, FALSE);
if (buf == NULL)
return; return;
}
di = dict_find(dict, (char_u*)"all", -1); di = dict_find(dict, (char_u*)"all", -1);
if (di != NULL) if (di != NULL)

View File

@@ -767,6 +767,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1388,
/**/ /**/
1387, 1387,
/**/ /**/