Skip to content

Commit 9ad89c6

Browse files
committed
patch 8.0.1223: crash when using autocomplete and tab pages
Problem: Crash when using autocomplete and tab pages. Solution: Check if the current tab changed. (Christian Brabandt, closes #2239)
1 parent ce11de8 commit 9ad89c6

4 files changed

Lines changed: 48 additions & 2 deletions

File tree

src/misc1.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,8 @@ ins_char_bytes(char_u *buf, int charlen)
23132313

23142314
/* Copy bytes after the changed character(s). */
23152315
p = newp + col;
2316-
mch_memmove(p + newlen, oldp + col + oldlen,
2316+
if (linelen > col + oldlen)
2317+
mch_memmove(p + newlen, oldp + col + oldlen,
23172318
(size_t)(linelen - col - oldlen));
23182319

23192320
/* Insert or overwrite the new character. */

src/popupmnu.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ pum_set_selected(int n, int repeat)
566566
&& vim_strchr(p_cot, 'p') != NULL)
567567
{
568568
win_T *curwin_save = curwin;
569+
tabpage_T *curtab_save = curtab;
569570
int res = OK;
570571

571572
/* Open a preview window. 3 lines by default. Prefer
@@ -653,8 +654,13 @@ pum_set_selected(int n, int repeat)
653654
curwin->w_cursor.lnum = 1;
654655
curwin->w_cursor.col = 0;
655656

656-
if (curwin != curwin_save && win_valid(curwin_save))
657+
if ((curwin != curwin_save && win_valid(curwin_save))
658+
|| (curtab != curtab_save
659+
&& valid_tabpage(curtab_save)))
657660
{
661+
if (curtab != curtab_save && valid_tabpage(curtab_save))
662+
goto_tabpage_tp(curtab_save, FALSE, FALSE);
663+
658664
/* When the first completion is done and the preview
659665
* window is not resized, skip the preview window's
660666
* status line redrawing. */

src/testdir/test_popup.vim

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,4 +661,41 @@ func Test_popup_and_window_resize()
661661
bwipe!
662662
endfunc
663663

664+
func Test_popup_and_preview_autocommand()
665+
" This used to crash Vim
666+
if !has('python')
667+
return
668+
endif
669+
let h = winheight(0)
670+
if h < 15
671+
return
672+
endif
673+
new
674+
augroup MyBufAdd
675+
au!
676+
au BufAdd * nested tab sball
677+
augroup END
678+
set omnifunc=pythoncomplete#Complete
679+
call setline(1, 'import os')
680+
" make the line long
681+
call setline(2, ' os.')
682+
$
683+
call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<enter>\<esc>", 'tx')
684+
call assert_equal(["import os", " os.EX_IOERR", ''], getline(1,'$'))
685+
call assert_equal(1, winnr('$'))
686+
" previewwindow option is not set
687+
call assert_equal(0, &previewwindow)
688+
norm! gt
689+
call assert_equal(0, &previewwindow)
690+
norm! gT
691+
call assert_equal(12, tabpagenr('$'))
692+
tabonly
693+
pclose
694+
augroup MyBufAdd
695+
au!
696+
augroup END
697+
augroup! MyBufAdd
698+
bw!
699+
endfunc
700+
664701
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1223,
764766
/**/
765767
1222,
766768
/**/

0 commit comments

Comments
 (0)