From 55821948cfb553bcf8bbb23f77a0f43070b4fdb0 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 17 Feb 2019 19:03:25 -0500 Subject: [PATCH 1/4] vim-patch:8.1.0945: internal error when using pattern with NL in the range Problem: Internal error when using pattern with NL in the range. Solution: Use an actual newline for the range. (closes vim/vim#3989) Also fix error message. (Dominique Pelle) https://github.com/vim/vim/commit/a5483448cba6997517003a22a8029f0de1007d0e --- src/nvim/regexp_nfa.c | 3 ++- src/nvim/testdir/test_regexp_latin.vim | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 08ef7da9c1..4e5f855e7f 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -1692,7 +1692,8 @@ collection: MB_PTR_ADV(regparse); if (*regparse == 'n') - startc = reg_string ? NL : NFA_NEWL; + startc = (reg_string || emit_range || regparse[1] == '-') + ? NL : NFA_NEWL; else if (*regparse == 'd' || *regparse == 'o' || *regparse == 'x' diff --git a/src/nvim/testdir/test_regexp_latin.vim b/src/nvim/testdir/test_regexp_latin.vim index 8528412806..e31bb08b19 100644 --- a/src/nvim/testdir/test_regexp_latin.vim +++ b/src/nvim/testdir/test_regexp_latin.vim @@ -30,3 +30,11 @@ func Test_equivalence_re2() set re=2 call s:equivalence_test() endfunc + +func Test_range_with_newline() + new + call setline(1, "a") + call assert_equal(0, search("[ -*\\n- ]")) + call assert_equal(0, search("[ -*\\t-\\n]")) + bwipe! +endfunc From d8b4fb7838eb6e9ff907bb014144fef9b6cd2933 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 17 Feb 2019 19:14:40 -0500 Subject: [PATCH 2/4] lint --- src/nvim/regexp_nfa.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 4e5f855e7f..d34e653058 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -1691,16 +1691,16 @@ collection: ) { MB_PTR_ADV(regparse); - if (*regparse == 'n') + if (*regparse == 'n') { startc = (reg_string || emit_range || regparse[1] == '-') ? NL : NFA_NEWL; - else if (*regparse == 'd' - || *regparse == 'o' - || *regparse == 'x' - || *regparse == 'u' - || *regparse == 'U' - ) { - /* TODO(RE) This needs more testing */ + } else if (*regparse == 'd' + || *regparse == 'o' + || *regparse == 'x' + || *regparse == 'u' + || *regparse == 'U' + ) { + // TODO(RE): This needs more testing startc = coll_get_char(); got_coll_char = true; MB_PTR_BACK(old_regparse, regparse); From 279ecaff00b5f7fed25cba0d6f131cb042420b20 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 17 Feb 2019 19:34:19 -0500 Subject: [PATCH 3/4] vim-patch:8.1.0934: invalid memory access in search pattern Problem: Invalid memory access in search pattern. (Kuang-che Wu) Solution: Check for incomplete equivalence class. (closes vim/vim#3970) https://github.com/vim/vim/commit/985079c514e9ab85598b7bca019c77d3e42526f5 --- src/nvim/regexp.c | 2 +- src/nvim/testdir/test_regexp_latin.vim | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index a70b150e9b..b7fc39fdb3 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -772,7 +772,7 @@ static int get_equi_class(char_u **pp) int l = 1; char_u *p = *pp; - if (p[1] == '=') { + if (p[1] == '=' && p[2] != NUL) { l = (*mb_ptr2len)(p + 2); if (p[l + 2] == '=' && p[l + 3] == ']') { c = utf_ptr2char(p + 2); diff --git a/src/nvim/testdir/test_regexp_latin.vim b/src/nvim/testdir/test_regexp_latin.vim index e31bb08b19..adbded128f 100644 --- a/src/nvim/testdir/test_regexp_latin.vim +++ b/src/nvim/testdir/test_regexp_latin.vim @@ -38,3 +38,10 @@ func Test_range_with_newline() call assert_equal(0, search("[ -*\\t-\\n]")) bwipe! endfunc + +func Test_get_equi_class() + new + " Incomplete equivalence class caused invalid memory access + s/^/[[= + call assert_equal(1, search(getline(1))) +endfunc From 486234ab3db56621767bea18a1783d289b660764 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 17 Feb 2019 19:36:21 -0500 Subject: [PATCH 4/4] vim-patch:8.1.0937: invalid memory access in search pattern Problem: Invalid memory access in search pattern. (Kuang-che Wu) Solution: Check for incomplete collation element. (Dominique Pelle, closes vim/vim#3985) https://github.com/vim/vim/commit/f1b57ab2ab18032d19f64bff7d22f3adb3fe93f7 --- src/nvim/regexp.c | 2 +- src/nvim/testdir/test_regexp_latin.vim | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index b7fc39fdb3..53479294de 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1103,7 +1103,7 @@ static int get_coll_element(char_u **pp) int l = 1; char_u *p = *pp; - if (p[0] != NUL && p[1] == '.') { + if (p[0] != NUL && p[1] == '.' && p[2] != NUL) { l = utfc_ptr2len(p + 2); if (p[l + 2] == '.' && p[l + 3] == ']') { c = utf_ptr2char(p + 2); diff --git a/src/nvim/testdir/test_regexp_latin.vim b/src/nvim/testdir/test_regexp_latin.vim index adbded128f..eb8f69ef15 100644 --- a/src/nvim/testdir/test_regexp_latin.vim +++ b/src/nvim/testdir/test_regexp_latin.vim @@ -44,4 +44,6 @@ func Test_get_equi_class() " Incomplete equivalence class caused invalid memory access s/^/[[= call assert_equal(1, search(getline(1))) + s/.*/[[. + call assert_equal(1, search(getline(1))) endfunc