@@ -2642,13 +2642,15 @@ buflist_findpat(
26422642 if (* p == '^' && !(attempt & 1 )) // add/remove '^'
26432643 ++ p ;
26442644 regmatch .regprog = vim_regcomp (p , magic_isset () ? RE_MAGIC : 0 );
2645- if (regmatch .regprog == NULL )
2646- {
2647- vim_free (pat );
2648- return -1 ;
2649- }
26502645
26512646 FOR_ALL_BUFS_FROM_LAST (buf )
2647+ {
2648+ if (regmatch .regprog == NULL )
2649+ {
2650+ // invalid pattern, possibly after switching engine
2651+ vim_free (pat );
2652+ return -1 ;
2653+ }
26522654 if (buf -> b_p_bl == find_listed
26532655#ifdef FEAT_DIFF
26542656 && (!diffmode || diff_mode_buf (buf ))
@@ -2674,6 +2676,7 @@ buflist_findpat(
26742676 }
26752677 match = buf -> b_fnum ; // remember first match
26762678 }
2679+ }
26772680
26782681 vim_regfree (regmatch .regprog );
26792682 if (match >= 0 ) // found one match
@@ -2766,12 +2769,6 @@ ExpandBufnames(
27662769 if (attempt > 0 && patc == pat )
27672770 break ; // there was no anchor, no need to try again
27682771 regmatch .regprog = vim_regcomp (patc + attempt * 11 , RE_MAGIC );
2769- if (regmatch .regprog == NULL )
2770- {
2771- if (patc != pat )
2772- vim_free (patc );
2773- return FAIL ;
2774- }
27752772 }
27762773
27772774 // round == 1: Count the matches.
@@ -2792,7 +2789,16 @@ ExpandBufnames(
27922789#endif
27932790
27942791 if (!fuzzy )
2792+ {
2793+ if (regmatch .regprog == NULL )
2794+ {
2795+ // invalid pattern, possibly after recompiling
2796+ if (patc != pat )
2797+ vim_free (patc );
2798+ return FAIL ;
2799+ }
27952800 p = buflist_match (& regmatch , buf , p_wic );
2801+ }
27962802 else
27972803 {
27982804 p = NULL ;
@@ -2921,6 +2927,7 @@ ExpandBufnames(
29212927
29222928/*
29232929 * Check for a match on the file name for buffer "buf" with regprog "prog".
2930+ * Note that rmp->regprog may become NULL when switching regexp engine.
29242931 */
29252932 static char_u *
29262933buflist_match (
@@ -2939,7 +2946,8 @@ buflist_match(
29392946}
29402947
29412948/*
2942- * Try matching the regexp in "prog" with file name "name".
2949+ * Try matching the regexp in "rmp->regprog" with file name "name".
2950+ * Note that rmp->regprog may become NULL when switching regexp engine.
29432951 * Return "name" when there is a match, NULL when not.
29442952 */
29452953 static char_u *
@@ -2951,7 +2959,8 @@ fname_match(
29512959 char_u * match = NULL ;
29522960 char_u * p ;
29532961
2954- if (name != NULL )
2962+ // extra check for valid arguments
2963+ if (name != NULL && rmp -> regprog != NULL )
29552964 {
29562965 // Ignore case when 'fileignorecase' or the argument is set.
29572966 rmp -> rm_ic = p_fic || ignore_case ;
0 commit comments