Dominique, thanks for catching this.
This was caused by my patch, sorry.
The problem is that backwards compatible versions of v: variables are
not handled properly (VV_COMPAT variables in vimvars).
These are:
count
errmsg
shell_error
this_session
version
For some, the code wrongly retrieves the vardict according to the
initial character:
shell_error -> s: variables of the current script
this_session -> t: variables of the current tab
version -> v: variables
So no crashes for these variables, but checking the wrong dict lock.
Only "count" and "errmsg" do not start with the character of a variable
scope, so the vardict is NULL.
The lookup of the variable scope dict needs to handle all variables
specially that can appear without a scope prefix. These are global
variables in global scope, function-local variables in function-local
scope, and the backwards compatible vim variables.
Your patch works because "count" is readonly, and "errmsg" is fixed (but
writeable), and fixed is checked as well.
I made a patch that adds the missing handling for compatible vim
variables, so that the actual dict lock is checked.
Also, a NULL vardict means that the variable scope could not be found.
This should never happen. I added an internal error for that case.
I also went back to the original order, now that it works. I find it
much more readable when first collecting the information and then doing
the checks en bloc.
Sigh... I remember working on this for the original patch, but then got
sidetracked with many other things that needed to be checked in the code
(e.g. special handling for b:changetick ...). Then I thought it was
already handled. Probably because I tested only ":undel version" or
some such.
---
src/eval.c | 33 +++++++++++++++++++--------------
src/testdir/test_unlet.vim | 6 ++++++
2 files changed, 25 insertions(+), 14 deletions(-)
Index: b/src/eval.c
===================================================================
--- a/src/eval.c 2016-01-09 06:00:19.530864146 +0100
+++ b/src/eval.c 2016-01-09 06:05:46.574253322 +0100
@@ -3738,25 +3738,30 @@ do_unlet(name, forceit)
ht = find_var_ht(name, &varname);
if (ht != NULL && *varname != NUL)
{
+ if (ht == &globvarht)
+ d = &globvardict;
+ else if (current_funccal != NULL
+ && ht == ¤t_funccal->l_vars.dv_hashtab)
+ d = ¤t_funccal->l_vars;
+ else if (ht == &compat_hashtab)
+ d = &vimvardict;
+ else
+ {
+ di = find_var_in_ht(ht, *name, (char_u *)"", FALSE);
+ d = di->di_tv.vval.v_dict;
+ }
+ if (d == NULL)
+ {
+ EMSG2(_(e_intern2), "do_unlet()");
+ return FAIL;
+ }
hi = hash_find(ht, varname);
if (!HASHITEM_EMPTY(hi))
{
di = HI2DI(hi);
if (var_check_fixed(di->di_flags, name, FALSE)
- || var_check_ro(di->di_flags, name, FALSE))
- return FAIL;
-
- if (ht == &globvarht)
- d = &globvardict;
- else if (current_funccal != NULL
- && ht == ¤t_funccal->l_vars.dv_hashtab)
- d = ¤t_funccal->l_vars;
- else
- {
- di = find_var_in_ht(ht, *name, (char_u *)"", FALSE);
- d = di->di_tv.vval.v_dict;
- }
- if (d == NULL || tv_check_lock(d->dv_lock, name, FALSE))
+ || var_check_ro(di->di_flags, name, FALSE)
+ || (tv_check_lock(d->dv_lock, name, FALSE)))
return FAIL;
delete_var(ht, hi);
Index: b/src/testdir/test_unlet.vim
===================================================================
--- a/src/testdir/test_unlet.vim 2016-01-09 05:48:40.596254789 +0100
+++ b/src/testdir/test_unlet.vim 2016-01-09 06:00:23.522856546 +0100
@@ -7,6 +7,12 @@ func Test_read_only()
catch
call assert_true(v:exception =~ ':E795:')
endtry
+ try
+ " this caused a crash
+ unlet errmsg
+ catch
+ call assert_true(v:exception =~ ':E795:')
+ endtry
endfunc
func Test_existing()
--
Olaf Dabrunz (oda <at> fctrace.org)
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.