Skip to content

Commit 927495b

Browse files
committed
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Problem: Crash when using a popup window with "latin1" encoding. Solution: Don't use ScreenLinesUC when enc_utf8 is false. (closes #7241)
1 parent 32e5ec0 commit 927495b

4 files changed

Lines changed: 42 additions & 5 deletions

File tree

src/screen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ screen_line(
464464
// First char of a popup window may go on top of the right half of a
465465
// double-wide character. Clear the left half to avoid it getting the popup
466466
// window background color.
467-
if (coloff > 0 && ScreenLines[off_to] == 0
467+
if (coloff > 0 && enc_utf8
468+
&& ScreenLines[off_to] == 0
468469
&& ScreenLinesUC[off_to - 1] != 0
469470
&& (*mb_char2cells)(ScreenLinesUC[off_to - 1]) > 1)
470471
{

src/terminal.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,10 @@ update_snapshot(term_T *term)
18301830
width = cell.width;
18311831

18321832
cell2cellattr(&cell, &p[pos.col]);
1833+
if (width == 2)
1834+
// second cell of double-width character has the
1835+
// same attributes.
1836+
p[pos.col + 1] = p[pos.col];
18331837

18341838
// Each character can be up to 6 bytes.
18351839
if (ga_grow(&ga, VTERM_MAX_CHARS_PER_CELL * 6) == OK)
@@ -3639,6 +3643,7 @@ term_line2screenline(
36393643
}
36403644
#endif
36413645
else
3646+
// This will only store the lower byte of "c".
36423647
ScreenLines[off] = c;
36433648
}
36443649
ScreenAttrs[off] = cell2attr(term, wp, cell.attrs, cell.fg, cell.bg);
@@ -3647,13 +3652,20 @@ term_line2screenline(
36473652
++off;
36483653
if (cell.width == 2)
36493654
{
3650-
if (enc_utf8)
3651-
ScreenLinesUC[off] = NUL;
3652-
36533655
// don't set the second byte to NUL for a DBCS encoding, it
36543656
// has been set above
3655-
if (enc_utf8 || !has_mbyte)
3657+
if (enc_utf8)
3658+
{
3659+
ScreenLinesUC[off] = NUL;
36563660
ScreenLines[off] = NUL;
3661+
}
3662+
else if (!has_mbyte)
3663+
{
3664+
// Can't show a double-width character with a single-byte
3665+
// 'encoding', just use a space.
3666+
ScreenLines[off] = ' ';
3667+
ScreenAttrs[off] = ScreenAttrs[off - 1];
3668+
}
36573669

36583670
++pos->col;
36593671
++off;

src/testdir/test_popupwin.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,6 +3685,28 @@ func Test_popupwin_filter_close_three_errors()
36853685
call delete('XtestPopupThreeErrors')
36863686
endfunc
36873687

3688+
func Test_popupwin_latin1_encoding()
3689+
CheckScreendump
3690+
CheckUnix
3691+
3692+
" When 'encoding' is a single-byte encoding a terminal window will mess up
3693+
" the display. Check that showing a popup on top of that doesn't crash.
3694+
let lines =<< trim END
3695+
set encoding=latin1
3696+
terminal cat Xmultibyte
3697+
call popup_create(['one', 'two', 'three', 'four'], #{line: 1, col: 10})
3698+
END
3699+
call writefile(lines, 'XtestPopupLatin')
3700+
call writefile([repeat("\u3042 ", 120)], 'Xmultibyte')
3701+
3702+
let buf = RunVimInTerminal('-S XtestPopupLatin', #{rows: 10})
3703+
3704+
call term_sendkeys(buf, ":q\<CR>")
3705+
call StopVimInTerminal(buf)
3706+
call delete('XtestPopupLatin')
3707+
call delete('Xmultibyte')
3708+
endfunc
3709+
36883710
func Test_popupwin_atcursor_far_right()
36893711
new
36903712

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
1963,
753755
/**/
754756
1962,
755757
/**/

0 commit comments

Comments
 (0)