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.

b62dc5e782

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq 2023-01-17 17:02:25 +08:00 committed by GitHub
parent b4d669e7ac
commit ddd69a6c81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 11 deletions

View File

@ -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.
///

View File

@ -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