]> granicus.if.org Git - vim/commitdiff
patch 7.4.1755 v7.4.1755
authorBram Moolenaar <Bram@vim.org>
Wed, 20 Apr 2016 12:59:29 +0000 (14:59 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 20 Apr 2016 12:59:29 +0000 (14:59 +0200)
Problem:    When using getreg() on a non-existing register a NULL list is
            returned. (Bjorn Linse)
Solution:   Allocate an empty list. Add a test.

src/eval.c
src/testdir/test_expr.vim
src/version.c

index bd4a11a8af0f808d2f00dac10b7f22990196c8c2..28cc2f1a79af16082d3b3ad26ebbeb07171babc5 100644 (file)
@@ -6051,7 +6051,7 @@ list_alloc(void)
 }
 
 /*
- * Allocate an empty list for a return value.
+ * Allocate an empty list for a return value, with reference count set.
  * Returns OK or FAIL.
  */
     int
@@ -13173,7 +13173,9 @@ f_getreg(typval_T *argvars, typval_T *rettv)
        rettv->v_type = VAR_LIST;
        rettv->vval.v_list = (list_T *)get_reg_contents(regname,
                                      (arg2 ? GREG_EXPR_SRC : 0) | GREG_LIST);
-       if (rettv->vval.v_list != NULL)
+       if (rettv->vval.v_list == NULL)
+           rettv_list_alloc(rettv);
+       else
            ++rettv->vval.v_list->lv_refcount;
     }
     else
index c8c8e2c2a4c8b7f6a5ea30d87c020cf1e70cd9f5..a726933740818d9200c5152eaa6e007478b9b16d 100644 (file)
@@ -74,3 +74,12 @@ func Test_strcharpart()
 
   call assert_equal('a', strcharpart('axb', -1, 2))
 endfunc
+
+func Test_getreg_empty_list()
+  call assert_equal('', getreg('x'))
+  call assert_equal([], getreg('x', 1, 1))
+  let x = getreg('x', 1, 1)
+  let y = x
+  call add(x, 'foo')
+  call assert_equal(['foo'], y)
+endfunc
index 20197c51545d10e36cee4e97b5db1597d7e591c8..393b75d1d3276f27a4fe513a603b520c15cb918c 100644 (file)
@@ -748,6 +748,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1755,
 /**/
     1754,
 /**/