On 09-Jan-16, Olaf Dabrunz wrote:
> Your patch works because "count" is readonly, and "errmsg" is fixed (but
> writeable), and fixed is checked as well.
Actually, all of these variables are fixed, and that is checked first.
> 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.
And in that case the holding dictitem is already NULL. The patch below
propagates the NULL to the dict, so a crash is avoided and the error
message can be printed.
Also, removed a redundant pair of braces.
> already handled. Probably because I tested only ":undel version" or
... ":unlet version" ...
---
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 13:52:52.952314067 +0100
+++ b/src/eval.c 2016-01-09 13:54:34.236166085 +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 == NULL ? NULL : 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 13:52:52.956314062 +0100
+++ b/src/testdir/test_unlet.vim 2016-01-09 13:53:34.640253069 +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.