diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/eval.c | 26 | ||||
| -rw-r--r-- | src/nvim/testdir/test_search.vim | 15 | ||||
| -rw-r--r-- | src/nvim/version.c | 2 | 
3 files changed, 32 insertions, 11 deletions
| diff --git a/src/nvim/eval.c b/src/nvim/eval.c index ef3a8cada1..c42929ef7c 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -14203,6 +14203,8 @@ do_searchpair (    int nest = 1;    int options = SEARCH_KEEP;    proftime_T tm; +  size_t pat2_len; +  size_t pat3_len;    /* Make 'cpoptions' empty, the 'l' flag should not be used here. */    save_cpo = p_cpo; @@ -14211,18 +14213,22 @@ do_searchpair (    /* Set the time limit, if there is one. */    tm = profile_setlimit(time_limit); -  /* Make two search patterns: start/end (pat2, for in nested pairs) and -   * start/middle/end (pat3, for the top pair). */ -  pat2 = xmalloc(STRLEN(spat) + STRLEN(epat) + 15); -  pat3 = xmalloc(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 23); -  sprintf((char *)pat2, "\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat); -  if (*mpat == NUL) +  // Make two search patterns: start/end (pat2, for in nested pairs) and +  // start/middle/end (pat3, for the top pair). +  pat2_len = STRLEN(spat) + STRLEN(epat) + 17; +  pat2 = xmalloc(pat2_len); +  pat3_len = STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 25; +  pat3 = xmalloc(pat3_len); +  snprintf((char *)pat2, pat2_len, "\\m\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat); +  if (*mpat == NUL) {      STRCPY(pat3, pat2); -  else -    sprintf((char *)pat3, "\\(%s\\m\\)\\|\\(%s\\m\\)\\|\\(%s\\m\\)", -        spat, epat, mpat); -  if (flags & SP_START) +  } else { +    snprintf((char *)pat3, pat3_len, +             "\\m\\(%s\\m\\)\\|\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat, mpat); +  } +  if (flags & SP_START) {      options |= SEARCH_START; +  }    save_cursor = curwin->w_cursor;    pos = curwin->w_cursor; diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 2106fc2dec..a333e7f206 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -283,3 +283,18 @@ func Test_use_sub_pat()    call X()    bwipe!  endfunc + +func Test_searchpair() +  new +  call setline(1, ['other code here', '', '[', '" cursor here', ']']) +  4 +  let a=searchpair('\[','',']','bW') +  call assert_equal(3, a) +  set nomagic +  4 +  let a=searchpair('\[','',']','bW') +  call assert_equal(3, a) +  set magic +  q! +endfunc + diff --git a/src/nvim/version.c b/src/nvim/version.c index aa7c613f3a..d4d2af2f26 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -805,7 +805,7 @@ static const int included_patches[] = {    150,    // 149,    // 148, -  // 147, +  147,    146,    // 145 NA    // 144 NA | 
