Mirror of the Vim source from https://github.com/vim/vim
リビジョン | c3570bdc93eb1b6e79fa0d2cf29cf27ae07de1d1 (tree) |
---|---|
日時 | 2022-05-15 23:00:03 |
作者 | Bram Moolenaar <Bram@vim....> |
コミッター | Bram Moolenaar |
patch 8.2.4959: using NULL regexp program
Commit: https://github.com/vim/vim/commit/b62dc5e7825bc195efe3041d5b3a9f1528359e1c
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 15 14:50:12 2022 +0100
@@ -2642,13 +2642,15 @@ | ||
2642 | 2642 | if (*p == '^' && !(attempt & 1)) // add/remove '^' |
2643 | 2643 | ++p; |
2644 | 2644 | regmatch.regprog = vim_regcomp(p, magic_isset() ? RE_MAGIC : 0); |
2645 | - if (regmatch.regprog == NULL) | |
2646 | - { | |
2647 | - vim_free(pat); | |
2648 | - return -1; | |
2649 | - } | |
2650 | 2645 | |
2651 | 2646 | 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 | + } | |
2652 | 2654 | if (buf->b_p_bl == find_listed |
2653 | 2655 | #ifdef FEAT_DIFF |
2654 | 2656 | && (!diffmode || diff_mode_buf(buf)) |
@@ -2674,6 +2676,7 @@ | ||
2674 | 2676 | } |
2675 | 2677 | match = buf->b_fnum; // remember first match |
2676 | 2678 | } |
2679 | + } | |
2677 | 2680 | |
2678 | 2681 | vim_regfree(regmatch.regprog); |
2679 | 2682 | if (match >= 0) // found one match |
@@ -2766,12 +2769,6 @@ | ||
2766 | 2769 | if (attempt > 0 && patc == pat) |
2767 | 2770 | break; // there was no anchor, no need to try again |
2768 | 2771 | 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 | - } | |
2775 | 2772 | } |
2776 | 2773 | |
2777 | 2774 | // round == 1: Count the matches. |
@@ -2792,7 +2789,16 @@ | ||
2792 | 2789 | #endif |
2793 | 2790 | |
2794 | 2791 | 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 | + } | |
2795 | 2800 | p = buflist_match(®match, buf, p_wic); |
2801 | + } | |
2796 | 2802 | else |
2797 | 2803 | { |
2798 | 2804 | p = NULL; |
@@ -2921,6 +2927,7 @@ | ||
2921 | 2927 | |
2922 | 2928 | /* |
2923 | 2929 | * 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. | |
2924 | 2931 | */ |
2925 | 2932 | static char_u * |
2926 | 2933 | buflist_match( |
@@ -2939,7 +2946,8 @@ | ||
2939 | 2946 | } |
2940 | 2947 | |
2941 | 2948 | /* |
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. | |
2943 | 2951 | * Return "name" when there is a match, NULL when not. |
2944 | 2952 | */ |
2945 | 2953 | static char_u * |
@@ -2951,7 +2959,8 @@ | ||
2951 | 2959 | char_u *match = NULL; |
2952 | 2960 | char_u *p; |
2953 | 2961 | |
2954 | - if (name != NULL) | |
2962 | + // extra check for valid arguments | |
2963 | + if (name != NULL && rmp->regprog != NULL) | |
2955 | 2964 | { |
2956 | 2965 | // Ignore case when 'fileignorecase' or the argument is set. |
2957 | 2966 | rmp->rm_ic = p_fic || ignore_case; |
@@ -419,6 +419,12 @@ | ||
419 | 419 | vsplit 00000000000000000000000000 |
420 | 420 | silent! buf [0--]\&\zs*\zs*e |
421 | 421 | bwipe! |
422 | + | |
423 | + " similar case with different code path | |
424 | + split 0 | |
425 | + edit ÿ | |
426 | + silent! buf [0--]\&\zs*\zs*0 | |
427 | + bwipe! | |
422 | 428 | endfunc |
423 | 429 | |
424 | 430 | " Test for the 'maxmem' and 'maxmemtot' options |
@@ -747,6 +747,8 @@ | ||
747 | 747 | static int included_patches[] = |
748 | 748 | { /* Add new patch number below this line */ |
749 | 749 | /**/ |
750 | + 4959, | |
751 | +/**/ | |
750 | 752 | 4958, |
751 | 753 | /**/ |
752 | 754 | 4957, |