From 3c6eb9871a9a7423e57f5c47e090457b26b6407b Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 8 Aug 2018 21:47:35 -0400 Subject: vim-patch:8.0.1004: matchstrpos() without a match returns too many items Problem: Matchstrpos() without a match returns too many items. Solution: Also remove the second item when the position is beyond the end of the string. (Hirohito Higashi) Use an enum for the type. https://github.com/vim/vim/commit/8d9f0ef5c6a6f6d19c3d02690e1ee347a70b8452 --- src/nvim/eval.c | 4 ++-- src/nvim/testdir/test_match.vim | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 9765b04922..d9765af1dc 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -12424,13 +12424,13 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv, vim_regfree(regmatch.regprog); } - if (type == kSomeMatchStrPos && l == NULL) { +theend: + if (type == kSomeMatchStrPos && l == NULL && rettv->vval.v_list != NULL) { // matchstrpos() without a list: drop the second item list_T *const ret_l = rettv->vval.v_list; tv_list_item_remove(ret_l, TV_LIST_ITEM_NEXT(ret_l, tv_list_first(ret_l))); } -theend: xfree(tofree); p_cpo = save_cpo; } diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index 066bb2f6a1..5602724b7d 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -152,13 +152,10 @@ endfunc func Test_matchstrpos() call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing')) - call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing', 2)) - call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5)) - + call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8)) call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing')) - call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img')) endfunc -- cgit From fe6cf2812b819297602ce355f8cfea157d64e110 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 8 Aug 2018 22:37:07 -0400 Subject: vim-patch:8.0.1105: match() and matchend() are not tested Problem: match() and matchend() are not tested. Solution: Add tests. (Ozaki Kiichi, closes vim/vim#2088) https://github.com/vim/vim/commit/1190cf68e27a123cf9f6fb57897782a3b9f7b810 --- src/nvim/testdir/test_functions.vim | 36 ++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_match.vim | 11 +---------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 3b16f2ce9f..285c4e6327 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -573,10 +573,46 @@ func Test_strridx() call assert_equal(-1, strridx('hello', 'hello world')) endfunc +func Test_match_func() + call assert_equal(4, match('testing', 'ing')) + call assert_equal(4, match('testing', 'ing', 2)) + call assert_equal(-1, match('testing', 'ing', 5)) + call assert_equal(-1, match('testing', 'ing', 8)) + call assert_equal(1, match(['vim', 'testing', 'execute'], 'ing')) + call assert_equal(-1, match(['vim', 'testing', 'execute'], 'img')) +endfunc + func Test_matchend() call assert_equal(7, matchend('testing', 'ing')) call assert_equal(7, matchend('testing', 'ing', 2)) call assert_equal(-1, matchend('testing', 'ing', 5)) + call assert_equal(-1, matchend('testing', 'ing', 8)) + call assert_equal(match(['vim', 'testing', 'execute'], 'ing'), matchend(['vim', 'testing', 'execute'], 'ing')) + call assert_equal(match(['vim', 'testing', 'execute'], 'img'), matchend(['vim', 'testing', 'execute'], 'img')) +endfunc + +func Test_matchlist() + call assert_equal(['acd', 'a', '', 'c', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')) + call assert_equal(['d', '', '', '', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2)) + call assert_equal([], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 4)) +endfunc + +func Test_matchstr() + call assert_equal('ing', matchstr('testing', 'ing')) + call assert_equal('ing', matchstr('testing', 'ing', 2)) + call assert_equal('', matchstr('testing', 'ing', 5)) + call assert_equal('', matchstr('testing', 'ing', 8)) + call assert_equal('testing', matchstr(['vim', 'testing', 'execute'], 'ing')) + call assert_equal('', matchstr(['vim', 'testing', 'execute'], 'img')) +endfunc + +func Test_matchstrpos() + call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing')) + call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing', 2)) + call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5)) + call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8)) + call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing')) + call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img')) endfunc func Test_nextnonblank_prevnonblank() diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index 5602724b7d..e608a2e58b 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -1,5 +1,5 @@ " Test for :match, :2match, :3match, clearmatches(), getmatches(), matchadd(), -" matchaddpos(), matcharg(), matchdelete(), matchstrpos() and setmatches(). +" matchaddpos(), matcharg(), matchdelete(), and setmatches(). function Test_match() highlight MyGroup1 term=bold ctermbg=red guibg=red @@ -150,15 +150,6 @@ function Test_match() highlight MyGroup3 NONE endfunc -func Test_matchstrpos() - call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing')) - call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing', 2)) - call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5)) - call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8)) - call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing')) - call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img')) -endfunc - func Test_matchaddpos() syntax on set hlsearch -- cgit From a44588798564dae1dc28b31af49e38399888d9a2 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 8 Aug 2018 23:16:36 -0400 Subject: vim-patch:8.0.1410: hang when using count() with an empty string Problem: Hang when using count() with an empty string. Solution: Return zero for an empty string. (Dominique Pelle, closes vim/vim#2465) https://github.com/vim/vim/commit/338e47fdfdf0d918dae50a5cbf0cf4f7be45b4f0 --- runtime/doc/eval.txt | 4 ++-- src/nvim/eval.c | 2 +- src/nvim/testdir/test_functions.vim | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index b3ab0a4500..4c0ee6cc66 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2998,8 +2998,8 @@ count({comp}, {expr} [, {ic} [, {start}]]) *count()* When {ic} is given and it's |TRUE| then case is ignored. When {comp} is a string then the number of not overlapping - occurences of {expr} is returned. - + occurrences of {expr} is returned. Zero is returned when + {expr} is an empty string. *cscope_connection()* cscope_connection([{num} , {dbpath} [, {prepend}]]) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d9765af1dc..8db48062e9 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -7603,7 +7603,7 @@ static void f_count(typval_T *argvars, typval_T *rettv, FunPtr fptr) const char_u *expr = (char_u *)tv_get_string_chk(&argvars[1]); const char_u *p = argvars[0].vval.v_string; - if (!error && expr != NULL && p != NULL) { + if (!error && expr != NULL && *expr != NUL && p != NULL) { if (ic) { const size_t len = STRLEN(expr); diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 285c4e6327..63794a7a85 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -723,6 +723,7 @@ func Test_count() call assert_equal(0, count("foo", "O")) call assert_equal(2, count("foo", "O", 1)) call assert_equal(2, count("fooooo", "oo")) + call assert_equal(0, count("foo", "")) endfunc func Test_changenr() -- cgit From 4420dc3067a776271a94080a4b1b42a1e74bb2dc Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 9 Aug 2018 00:51:40 -0400 Subject: vim-patch:8.0.1421: accessing invalid memory with overlong byte sequence Problem: Accessing invalid memory with overlong byte sequence. Solution: Check for NUL character. (test by Dominique Pelle, closes vim/vim#2485) https://github.com/vim/vim/commit/e6640ad44e2186bd3642b972115496d347cd1fdd --- src/nvim/strings.c | 9 ++++++--- src/nvim/testdir/test_functions.vim | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 3f31914c03..d812aba048 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -344,14 +344,17 @@ char *strcase_save(const char *const orig, bool upper) char *p = res; while (*p != NUL) { - int l; - int c = utf_ptr2char((const char_u *)p); + int l = utf_ptr2len((const char_u *)p); + if (c == 0) { + // overlong sequence, use only the first byte + c = *p; + l = 1; + } int uc = upper ? mb_toupper(c) : mb_tolower(c); // Reallocate string when byte count changes. This is rare, // thus it's OK to do another malloc()/free(). - l = utf_ptr2len((const char_u *)p); int newl = utf_char2len(uc); if (newl != l) { // TODO(philix): use xrealloc() in strup_save() diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 63794a7a85..59445ebfe6 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -299,6 +299,11 @@ func Test_tolower() " Ⱥ (U+023A) and Ⱦ (U+023E) are the *only* code points to increase " in length (2 to 3 bytes) when lowercased. So let's test them. call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ")) + + " This call to tolower with invalid utf8 sequence used to cause access to + " invalid memory. + call tolower("\xC0\x80\xC0") + call tolower("123\xC0\x80\xC0") endfunc func Test_toupper() @@ -369,6 +374,11 @@ func Test_toupper() call assert_equal("ZŹŻŽƵẐẔ", toupper("ZŹŻŽƵẐẔ")) call assert_equal("Ⱥ Ⱦ", toupper("ⱥ ⱦ")) + + " This call to toupper with invalid utf8 sequence used to cause access to + " invalid memory. + call toupper("\xC0\x80\xC0") + call toupper("123\xC0\x80\xC0") endfunc " Tests for the mode() function -- cgit From 047dfcd29406350ef85a87a9e248b7b56261bd5f Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 9 Aug 2018 08:08:40 -0400 Subject: vim-patch:8.1.0008: no test for strwidth() Problem: No test for strwidth(). Solution: Add a test. (Dominique Pelle, closes vim/vim#2931) https://github.com/vim/vim/commit/42ab17b8e32352210c4e273a4a4161a287d2c159 --- src/nvim/testdir/test_functions.vim | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 59445ebfe6..53911382b6 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -96,6 +96,30 @@ func Test_min() " call assert_fails('call min(v:none)', 'E712:') endfunc +func Test_strwidth() + for aw in ['single', 'double'] + exe 'set ambiwidth=' . aw + call assert_equal(0, strwidth('')) + call assert_equal(1, strwidth("\t")) + call assert_equal(3, strwidth('Vim')) + call assert_equal(4, strwidth(1234)) + call assert_equal(5, strwidth(-1234)) + + if has('multi_byte') + call assert_equal(2, strwidth('😉')) + call assert_equal(17, strwidth('Eĥoŝanĝo ĉiuĵaŭde')) + call assert_equal((aw == 'single') ? 6 : 7, strwidth('Straße')) + endif + + call assert_fails('call strwidth({->0})', 'E729:') + call assert_fails('call strwidth([])', 'E730:') + call assert_fails('call strwidth({})', 'E731:') + call assert_fails('call strwidth(1.2)', 'E806:') + endfor + + set ambiwidth& +endfunc + func Test_str2nr() call assert_equal(0, str2nr('')) call assert_equal(1, str2nr('1')) -- cgit From 218fccaba4c897f294cb2f21a63fb1c76f387970 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 9 Aug 2018 09:25:10 -0400 Subject: vim-patch:8.1.0204: inputlist() is not tested Problem: inputlist() is not tested. Solution: Add a test. (Dominique Pelle, closes vim/vim#3240) https://github.com/vim/vim/commit/947b39e761b8a95cc1bd37ad0c2c30552238809a --- src/nvim/testdir/test_functions.vim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 53911382b6..754a7ca18a 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -841,6 +841,17 @@ func Test_col() bw! endfunc +func Test_inputlist() + call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\1\", 'tx') + call assert_equal(1, c) + call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\2\", 'tx') + call assert_equal(2, c) + call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\3\", 'tx') + call assert_equal(3, c) + + call assert_fails('call inputlist("")', 'E686:') +endfunc + func Test_balloon_show() if has('balloon_eval') " This won't do anything but must not crash either. -- cgit From 6ad8294d5cb3aa934c524141a5f3b86c769becfc Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 9 Aug 2018 09:48:59 -0400 Subject: vim-patch:8.1.0257: no test for pathshorten() Problem: No test for pathshorten(). Solution: Add a test. (Dominique Pelle, closes vim/vim#3295) https://github.com/vim/vim/commit/bfde0b482d25db43e9fc5a35c771b859b1eb8828 --- src/nvim/testdir/test_functions.vim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 754a7ca18a..6d0a6b9d5e 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -239,6 +239,21 @@ func Test_setbufvar_options() bwipe! endfunc +func Test_pathshorten() + call assert_equal('', pathshorten('')) + call assert_equal('foo', pathshorten('foo')) + call assert_equal('/foo', pathshorten('/foo')) + call assert_equal('f/', pathshorten('foo/')) + call assert_equal('f/bar', pathshorten('foo/bar')) + call assert_equal('f/b/foobar', pathshorten('foo/bar/foobar')) + call assert_equal('/f/b/foobar', pathshorten('/foo/bar/foobar')) + call assert_equal('.f/bar', pathshorten('.foo/bar')) + call assert_equal('~f/bar', pathshorten('~foo/bar')) + call assert_equal('~.f/bar', pathshorten('~.foo/bar')) + call assert_equal('.~f/bar', pathshorten('.~foo/bar')) + call assert_equal('~/f/bar', pathshorten('~/foo/bar')) +endfunc + func Test_strpart() call assert_equal('de', strpart('abcdefg', 3, 2)) call assert_equal('ab', strpart('abcdefg', -2, 4)) -- cgit From 8ad46a25cb8f774db378f29b0e4c43bce524b76e Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 11 Aug 2018 19:30:08 -0400 Subject: eval: match in find_some_match() is bool --- src/nvim/eval.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 8db48062e9..22cb544f54 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -12227,7 +12227,7 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv, long start = 0; long nth = 1; colnr_T startcol = 0; - int match = 0; + bool match = false; list_T *l = NULL; listitem_T *li = NULL; long idx = 0; @@ -12325,7 +12325,7 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv, for (;; ) { if (l != NULL) { if (li == NULL) { - match = FALSE; + match = false; break; } xfree(tofree); @@ -12351,7 +12351,7 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv, startcol = (colnr_T)(regmatch.startp[0] + (*mb_ptr2len)(regmatch.startp[0]) - str); if (startcol > (colnr_T)len || str + startcol <= regmatch.startp[0]) { - match = FALSE; + match = false; break; } } -- cgit