Skip to content

Commit a7d36b7

Browse files
zeertzjqbrammool
authored andcommitted
patch 9.0.1270: crash when using search stat in narrow screen
Problem: Crash when using search stat in narrow screen. Solution: Check length of message. (closes #11921)
1 parent b40c1de commit a7d36b7

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/search.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3154,7 +3154,11 @@ cmdline_search_stat(
31543154
len += 2;
31553155
}
31563156

3157-
mch_memmove(msgbuf + STRLEN(msgbuf) - len, t, len);
3157+
size_t msgbuf_len = STRLEN(msgbuf);
3158+
if (len > msgbuf_len)
3159+
len = msgbuf_len;
3160+
mch_memmove(msgbuf + msgbuf_len - len, t, len);
3161+
31583162
if (dirc == '?' && stat.cur == maxcount + 1)
31593163
stat.cur = -1;
31603164

src/testdir/test_search_stat.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,29 @@ func Test_searchcount_fails()
270270
call assert_fails('echo searchcount({"pos" : [1, 2, []]})', 'E745:')
271271
endfunc
272272

273+
func Test_search_stat_narrow_screen()
274+
" This used to crash Vim
275+
let save_columns = &columns
276+
try
277+
let after =<< trim [CODE]
278+
set laststatus=2
279+
set columns=16
280+
set shortmess-=S showcmd
281+
call setline(1, 'abc')
282+
call feedkeys("/abc\<CR>:quit!\<CR>")
283+
autocmd VimLeavePre * call writefile(["done"], "Xdone")
284+
[CODE]
285+
286+
if !RunVim([], after, '--clean')
287+
return
288+
endif
289+
call assert_equal("done", readfile("Xdone")[0])
290+
call delete('Xdone')
291+
finally
292+
let &columns = save_columns
293+
endtry
294+
endfunc
295+
273296
func Test_searchcount_in_statusline()
274297
CheckScreendump
275298

src/version.c

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

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1270,
698700
/**/
699701
1269,
700702
/**/

0 commit comments

Comments
 (0)