Skip to content

Commit af8af8b

Browse files
committed
patch 7.4.1051
Problem: Segfault when unletting "count". Solution: Check for readonly and locked first. (Dominique Pelle) Add a test.
1 parent c71982b commit af8af8b

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

src/eval.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3737,24 +3737,27 @@ do_unlet(name, forceit)
37373737
ht = find_var_ht(name, &varname);
37383738
if (ht != NULL && *varname != NUL)
37393739
{
3740-
if (ht == &globvarht)
3741-
d = &globvardict;
3742-
else if (current_funccal != NULL
3743-
&& ht == &current_funccal->l_vars.dv_hashtab)
3744-
d = &current_funccal->l_vars;
3745-
else
3746-
{
3747-
di = find_var_in_ht(ht, *name, (char_u *)"", FALSE);
3748-
d = di->di_tv.vval.v_dict;
3749-
}
37503740
hi = hash_find(ht, varname);
37513741
if (!HASHITEM_EMPTY(hi))
37523742
{
37533743
di = HI2DI(hi);
37543744
if (var_check_fixed(di->di_flags, name, FALSE)
3755-
|| var_check_ro(di->di_flags, name, FALSE)
3756-
|| tv_check_lock(d->dv_lock, name, FALSE))
3745+
|| var_check_ro(di->di_flags, name, FALSE))
37573746
return FAIL;
3747+
3748+
if (ht == &globvarht)
3749+
d = &globvardict;
3750+
else if (current_funccal != NULL
3751+
&& ht == &current_funccal->l_vars.dv_hashtab)
3752+
d = &current_funccal->l_vars;
3753+
else
3754+
{
3755+
di = find_var_in_ht(ht, *name, (char_u *)"", FALSE);
3756+
d = di->di_tv.vval.v_dict;
3757+
}
3758+
if (d == NULL || tv_check_lock(d->dv_lock, name, FALSE))
3759+
return FAIL;
3760+
37583761
delete_var(ht, hi);
37593762
return OK;
37603763
}

src/testdir/test_alot.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ source test_searchpos.vim
88
source test_set.vim
99
source test_sort.vim
1010
source test_undolevels.vim
11+
source test_unlet.vim

src/testdir/test_unlet.vim

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
" Tests for :unlet
2+
3+
func Test_read_only()
4+
try
5+
" this caused a crash
6+
unlet count
7+
catch
8+
call assert_true(v:exception =~ ':E795:')
9+
endtry
10+
endfunc
11+
12+
func Test_existing()
13+
let does_exist = 1
14+
call assert_true(exists('does_exist'))
15+
unlet does_exist
16+
call assert_false(exists('does_exist'))
17+
endfunc
18+
19+
func Test_not_existing()
20+
unlet! does_not_exist
21+
try
22+
unlet does_not_exist
23+
catch
24+
call assert_true(v:exception =~ ':E108:')
25+
endtry
26+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
1051,
744746
/**/
745747
1050,
746748
/**/

0 commit comments

Comments
 (0)