Skip to content

Commit 517ffbe

Browse files
committed
patch 7.4.1755
Problem: When using getreg() on a non-existing register a NULL list is returned. (Bjorn Linse) Solution: Allocate an empty list. Add a test.
1 parent c369133 commit 517ffbe

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/eval.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6051,7 +6051,7 @@ list_alloc(void)
60516051
}
60526052

60536053
/*
6054-
* Allocate an empty list for a return value.
6054+
* Allocate an empty list for a return value, with reference count set.
60556055
* Returns OK or FAIL.
60566056
*/
60576057
int
@@ -13173,7 +13173,9 @@ f_getreg(typval_T *argvars, typval_T *rettv)
1317313173
rettv->v_type = VAR_LIST;
1317413174
rettv->vval.v_list = (list_T *)get_reg_contents(regname,
1317513175
(arg2 ? GREG_EXPR_SRC : 0) | GREG_LIST);
13176-
if (rettv->vval.v_list != NULL)
13176+
if (rettv->vval.v_list == NULL)
13177+
rettv_list_alloc(rettv);
13178+
else
1317713179
++rettv->vval.v_list->lv_refcount;
1317813180
}
1317913181
else

src/testdir/test_expr.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,12 @@ func Test_strcharpart()
7474

7575
call assert_equal('a', strcharpart('axb', -1, 2))
7676
endfunc
77+
78+
func Test_getreg_empty_list()
79+
call assert_equal('', getreg('x'))
80+
call assert_equal([], getreg('x', 1, 1))
81+
let x = getreg('x', 1, 1)
82+
let y = x
83+
call add(x, 'foo')
84+
call assert_equal(['foo'], y)
85+
endfunc

src/version.c

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

749749
static int included_patches[] =
750750
{ /* Add new patch number below this line */
751+
/**/
752+
1755,
751753
/**/
752754
1754,
753755
/**/

0 commit comments

Comments
 (0)