diff options
-rw-r--r-- | src/nvim/buffer.c | 26 | ||||
-rw-r--r-- | src/nvim/testdir/test_buffer.vim | 6 |
2 files changed, 21 insertions, 11 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 32e0cf5acf..9dd5fdaea5 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2255,12 +2255,13 @@ int buflist_findpat(const char *pattern, const char *pattern_end, bool unlisted, regmatch_T regmatch; regmatch.regprog = vim_regcomp(p, magic_isset() ? RE_MAGIC : 0); - if (regmatch.regprog == NULL) { - xfree(pat); - return -1; - } FOR_ALL_BUFFERS_BACKWARDS(buf) { + if (regmatch.regprog == NULL) { + // invalid pattern, possibly after switching engine + xfree(pat); + return -1; + } if (buf->b_p_bl == find_listed && (!diffmode || diff_mode_buf(buf)) && buflist_match(®match, buf, false) != NULL) { @@ -2372,12 +2373,6 @@ int ExpandBufnames(char *pat, int *num_file, char ***file, int options) break; // there was no anchor, no need to try again } regmatch.regprog = vim_regcomp(patc + attempt * 11, RE_MAGIC); - if (regmatch.regprog == NULL) { - if (patc != pat) { - xfree(patc); - } - return FAIL; - } } int score = 0; @@ -2398,6 +2393,13 @@ int ExpandBufnames(char *pat, int *num_file, char ***file, int options) } if (!fuzzy) { + if (regmatch.regprog == NULL) { + // invalid pattern, possibly after recompiling + if (patc != pat) { + xfree(patc); + } + return FAIL; + } p = buflist_match(®match, buf, p_wic); } else { p = NULL; @@ -2495,6 +2497,7 @@ int ExpandBufnames(char *pat, int *num_file, char ***file, int options) } /// Check for a match on the file name for buffer "buf" with regprog "prog". +/// Note that rmp->regprog may become NULL when switching regexp engine. /// /// @param ignore_case When true, ignore case. Use 'fic' otherwise. static char *buflist_match(regmatch_T *rmp, buf_T *buf, bool ignore_case) @@ -2507,7 +2510,8 @@ static char *buflist_match(regmatch_T *rmp, buf_T *buf, bool ignore_case) return match; } -/// Try matching the regexp in "prog" with file name "name". +/// Try matching the regexp in "rmp->regprog" with file name "name". +/// Note that rmp->regprog may become NULL when switching regexp engine. /// /// @param ignore_case When true, ignore case. Use 'fileignorecase' otherwise. /// diff --git a/src/nvim/testdir/test_buffer.vim b/src/nvim/testdir/test_buffer.vim index 549aa691c8..9220cc17b9 100644 --- a/src/nvim/testdir/test_buffer.vim +++ b/src/nvim/testdir/test_buffer.vim @@ -423,6 +423,12 @@ func Test_buf_pattern_invalid() vsplit 00000000000000000000000000 silent! buf [0--]\&\zs*\zs*e bwipe! + + " similar case with different code path + split 0 + edit ΓΏ + silent! buf [0--]\&\zs*\zs*0 + bwipe! endfunc " Test for the 'maxmem' and 'maxmemtot' options |