]> granicus.if.org Git - vim/commitdiff
patch 7.4.1051 v7.4.1051
authorBram Moolenaar <Bram@vim.org>
Mon, 4 Jan 2016 21:05:24 +0000 (22:05 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 4 Jan 2016 21:05:24 +0000 (22:05 +0100)
Problem:    Segfault when unletting "count".
Solution:   Check for readonly and locked first. (Dominique Pelle)
            Add a test.

src/eval.c
src/testdir/test_alot.vim
src/testdir/test_unlet.vim [new file with mode: 0644]
src/version.c

index feaa71c33cf9e669c9bc5bf931b230274409cb6a..76dd65387a6cbf526b19563ed4e484b7d015551f 100644 (file)
@@ -3737,24 +3737,27 @@ 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 == &current_funccal->l_vars.dv_hashtab)
-           d = &current_funccal->l_vars;
-       else
-       {
-           di = find_var_in_ht(ht, *name, (char_u *)"", FALSE);
-           d = di->di_tv.vval.v_dict;
-       }
        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)
-                   || tv_check_lock(d->dv_lock, name, FALSE))
+                   || var_check_ro(di->di_flags, name, FALSE))
                return FAIL;
+
+           if (ht == &globvarht)
+               d = &globvardict;
+           else if (current_funccal != NULL
+                                && ht == &current_funccal->l_vars.dv_hashtab)
+               d = &current_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))
+               return FAIL;
+
            delete_var(ht, hi);
            return OK;
        }
index 9800afce7b1ddb432d9610d34d37d86917b93afc..413e71b54348b8659ffb794b4fb8018030ac7fb7 100644 (file)
@@ -8,3 +8,4 @@ source test_searchpos.vim
 source test_set.vim
 source test_sort.vim
 source test_undolevels.vim
+source test_unlet.vim
diff --git a/src/testdir/test_unlet.vim b/src/testdir/test_unlet.vim
new file mode 100644 (file)
index 0000000..f670599
--- /dev/null
@@ -0,0 +1,26 @@
+" Tests for :unlet
+
+func Test_read_only()
+  try
+    " this caused a crash
+    unlet count
+  catch
+    call assert_true(v:exception =~ ':E795:')
+  endtry
+endfunc
+
+func Test_existing()
+  let does_exist = 1
+  call assert_true(exists('does_exist'))
+  unlet does_exist
+  call assert_false(exists('does_exist'))
+endfunc
+
+func Test_not_existing()
+  unlet! does_not_exist
+  try
+    unlet does_not_exist
+  catch
+    call assert_true(v:exception =~ ':E108:')
+  endtry
+endfunc
index 470cce8a98ad65e15cbec889aa713327f08caf78..402fd0ab0465dcc55b6d1eb7f9d95168fcad2c79 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1051,
 /**/
     1050,
 /**/