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