diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2016-04-20 13:44:12 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2016-04-21 18:11:06 +0200 |
commit | ce17d031805ab548f26f5b2d519fb8e3bf1bbff1 (patch) | |
tree | 24afb43c916063c690d7a8f5fb319cac407aeb01 | |
parent | a7a0bf54e3f339f7bf1f97dee44546cdcd926b1d (diff) | |
download | rneovim-ce17d031805ab548f26f5b2d519fb8e3bf1bbff1.tar.gz rneovim-ce17d031805ab548f26f5b2d519fb8e3bf1bbff1.tar.bz2 rneovim-ce17d031805ab548f26f5b2d519fb8e3bf1bbff1.zip |
eval: let getreg() return valid list for an undefined register
vim-patch:7.4.1755
this prevents a crash when the list is used in setreg() later
-rw-r--r-- | src/nvim/eval.c | 5 | ||||
-rw-r--r-- | src/nvim/version.c | 1 | ||||
-rw-r--r-- | test/functional/legacy/eval_spec.lua | 22 | ||||
-rw-r--r-- | test/functional/shada/compatibility_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/shada/registers_spec.lua | 18 |
5 files changed, 36 insertions, 14 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index e9b1df6367..b51480afc6 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10096,9 +10096,10 @@ static void f_getreg(typval_T *argvars, typval_T *rettv) rettv->v_type = VAR_LIST; rettv->vval.v_list = get_reg_contents(regname, (arg2 ? kGRegExprSrc : 0) | kGRegList); - if (rettv->vval.v_list != NULL) { - rettv->vval.v_list->lv_refcount++; + if (rettv->vval.v_list == NULL) { + rettv->vval.v_list = list_alloc(); } + rettv->vval.v_list->lv_refcount++; } else { rettv->v_type = VAR_STRING; rettv->vval.v_string = get_reg_contents(regname, arg2 ? kGRegExprSrc : 0); diff --git a/src/nvim/version.c b/src/nvim/version.c index afd5639d30..5ead7cecbe 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -69,6 +69,7 @@ static char *features[] = { // clang-format off static int included_patches[] = { + 1755, 1654, 1652, 1643, diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua index d1ed96cc2e..3ff1092a4b 100644 --- a/test/functional/legacy/eval_spec.lua +++ b/test/functional/legacy/eval_spec.lua @@ -495,6 +495,28 @@ describe('eval', function() ' abcE4b10-4\000abcE4b10-4-2') end) + it('getreg("a",1,1) returns a valid list when "a is unset', function() + -- Precondition: "a is actually unset and "0 is nonempty + eq('', eval("getregtype('a')")) + eq('', eval("getreg('a')")) + execute("call setreg('0','text')") + + -- This used to return a NULL list + -- which setreg didn't handle + execute("let x = getreg('a',1,1)") + execute("call setreg('0',x)") + + -- nvim didn't crash and "0 was emptied + eq(2, eval("1+1")) + eq({}, eval("getreg('0',1,1)")) + + -- x is a mutable list + execute("let y = x") + eq({}, eval("y")) + execute("call add(x, 'item')") + eq({'item'}, eval("y")) + end) + it('search and expressions', function() execute('so test_eval_setup.vim') execute([=[call SetReg('/', ['abc/'])]=]) diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua index 774a1f1346..1fa88c58e5 100644 --- a/test/functional/shada/compatibility_spec.lua +++ b/test/functional/shada/compatibility_spec.lua @@ -270,9 +270,7 @@ describe('ShaDa forward compatibility support code', function() it('works with register item with type 10', function() wshada('\005\001\019\132\161na\162rX\194\162rc\145\196\001-\162rt\010') eq(0, exc_exec(sdrcmd(true))) - -- getreg may return empty list as list with NULL pointer which API - -- translates into nil for some reason. - eq(NIL, funcs.getreg('a', 1, 1) or {}) + eq({}, funcs.getreg('a', 1, 1)) eq('', funcs.getregtype('a')) nvim_command('wshada ' .. shada_fname) local found = 0 diff --git a/test/functional/shada/registers_spec.lua b/test/functional/shada/registers_spec.lua index d3af35cf7f..4043d94a69 100644 --- a/test/functional/shada/registers_spec.lua +++ b/test/functional/shada/registers_spec.lua @@ -43,9 +43,9 @@ describe('ShaDa support code', function() setreg('b', {'bca', 'abc', 'cba'}, 'b3') nvim_command('qall') reset() - eq({NIL, ''}, getreg('c')) - eq({NIL, ''}, getreg('l')) - eq({NIL, ''}, getreg('b')) + eq({{}, ''}, getreg('c')) + eq({{}, ''}, getreg('l')) + eq({{}, ''}, getreg('b')) end) it('does restore registers with zero <', function() @@ -67,9 +67,9 @@ describe('ShaDa support code', function() setreg('b', {'bca', 'abc', 'cba'}, 'b3') nvim_command('qall') reset() - eq({NIL, ''}, getreg('c')) - eq({NIL, ''}, getreg('l')) - eq({NIL, ''}, getreg('b')) + eq({{}, ''}, getreg('c')) + eq({{}, ''}, getreg('l')) + eq({{}, ''}, getreg('b')) end) it('does restore registers with zero "', function() @@ -103,7 +103,7 @@ describe('ShaDa support code', function() nvim_command('qall') reset() eq({{'d'}, 'v'}, getreg('o')) - eq({NIL, ''}, getreg('t')) + eq({{}, ''}, getreg('t')) end) it('does limit number of lines according to "', function() @@ -113,7 +113,7 @@ describe('ShaDa support code', function() nvim_command('qall') reset() eq({{'d'}, 'v'}, getreg('o')) - eq({NIL, ''}, getreg('t')) + eq({{}, ''}, getreg('t')) end) it('does limit number of lines according to < rather then "', function() @@ -125,7 +125,7 @@ describe('ShaDa support code', function() reset() eq({{'d'}, 'v'}, getreg('o')) eq({{'a', 'b', 'cde'}, 'V'}, getreg('t')) - eq({NIL, ''}, getreg('h')) + eq({{}, ''}, getreg('h')) end) it('dumps and loads register correctly when &encoding is not UTF-8', |