Skip to content

Commit 8ada6aa

Browse files
committed
patch 8.0.1416: crash when searching for a sentence
Problem: Crash when searching for a sentence. Solution: Return NUL when getting character at MAXCOL. (closes #2468)
1 parent 4ce46c2 commit 8ada6aa

5 files changed

Lines changed: 33 additions & 14 deletions

File tree

src/ex_docmd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4521,13 +4521,14 @@ get_address(
45214521
if (lnum != MAXLNUM)
45224522
curwin->w_cursor.lnum = lnum;
45234523
/*
4524-
* Start a forward search at the end of the line.
4524+
* Start a forward search at the end of the line (unless
4525+
* before the first line).
45254526
* Start a backward search at the start of the line.
45264527
* This makes sure we never match in the current
45274528
* line, and can match anywhere in the
45284529
* next/previous line.
45294530
*/
4530-
if (c == '/')
4531+
if (c == '/' && curwin->w_cursor.lnum > 0)
45314532
curwin->w_cursor.col = MAXCOL;
45324533
else
45334534
curwin->w_cursor.col = 0;

src/misc1.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2650,8 +2650,12 @@ del_lines(
26502650
int
26512651
gchar_pos(pos_T *pos)
26522652
{
2653-
char_u *ptr = ml_get_pos(pos);
2653+
char_u *ptr;
26542654

2655+
/* When searching columns is sometimes put at the end of a line. */
2656+
if (pos->col == MAXCOL)
2657+
return NUL;
2658+
ptr = ml_get_pos(pos);
26552659
#ifdef FEAT_MBYTE
26562660
if (has_mbyte)
26572661
return (*mb_ptr2char)(ptr);

src/misc2.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,24 +348,29 @@ inc_cursor(void)
348348
int
349349
inc(pos_T *lp)
350350
{
351-
char_u *p = ml_get_pos(lp);
351+
char_u *p;
352352

353-
if (*p != NUL) /* still within line, move to next char (may be NUL) */
353+
/* when searching position may be set to end of a line */
354+
if (lp->col != MAXCOL)
354355
{
355-
#ifdef FEAT_MBYTE
356-
if (has_mbyte)
356+
p = ml_get_pos(lp);
357+
if (*p != NUL) /* still within line, move to next char (may be NUL) */
357358
{
358-
int l = (*mb_ptr2len)(p);
359+
#ifdef FEAT_MBYTE
360+
if (has_mbyte)
361+
{
362+
int l = (*mb_ptr2len)(p);
359363

360-
lp->col += l;
361-
return ((p[l] != NUL) ? 0 : 2);
362-
}
364+
lp->col += l;
365+
return ((p[l] != NUL) ? 0 : 2);
366+
}
363367
#endif
364-
lp->col++;
368+
lp->col++;
365369
#ifdef FEAT_VIRTUALEDIT
366-
lp->coladd = 0;
370+
lp->coladd = 0;
367371
#endif
368-
return ((p[1] != NUL) ? 0 : 2);
372+
return ((p[1] != NUL) ? 0 : 2);
373+
}
369374
}
370375
if (lp->lnum != curbuf->b_ml.ml_line_count) /* there is a next line */
371376
{

src/testdir/test_search.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,3 +729,10 @@ func Test_look_behind()
729729
call search(getline("."))
730730
bwipe!
731731
endfunc
732+
733+
func Test_search_sentence()
734+
new
735+
" this used to cause a crash
736+
call assert_fails("/\\%'", 'E486')
737+
call assert_fails("/", 'E486')
738+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static char *(features[]) =
771771

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1416,
774776
/**/
775777
1415,
776778
/**/

0 commit comments

Comments
 (0)