aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/buffer.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-01-17 17:02:25 +0800
committerGitHub <noreply@github.com>2023-01-17 17:02:25 +0800
commitddd69a6c81c1a2595e81377503dd2b47f2c41b83 (patch)
treec5e1398766d5337ac26ae48246fa02a597382f00 /src/nvim/buffer.c
parentb4d669e7acd819cd5723b387a5a79023994d438d (diff)
downloadrneovim-ddd69a6c81c1a2595e81377503dd2b47f2c41b83.tar.gz
rneovim-ddd69a6c81c1a2595e81377503dd2b47f2c41b83.tar.bz2
rneovim-ddd69a6c81c1a2595e81377503dd2b47f2c41b83.zip
vim-patch:8.2.4959: using NULL regexp program (#21855)
Problem: Using NULL regexp program. Solution: Check for regexp program becoming NULL in more places. https://github.com/vim/vim/commit/b62dc5e7825bc195efe3041d5b3a9f1528359e1c Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/buffer.c')
-rw-r--r--src/nvim/buffer.c26
1 files changed, 15 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(&regmatch, 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(&regmatch, 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.
///