To: vim_dev@googlegroups.com Subject: Patch 8.2.1963 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1963 Problem: Crash when using a popup window with "latin1" encoding. Solution: Don't use ScreenLinesUC when enc_utf8 is false. (closes #7241) Files: src/screen.c, src/terminal.c, src/testdir/test_popupwin.vim *** ../vim-8.2.1962/src/screen.c 2020-10-28 20:19:56.376057067 +0100 --- src/screen.c 2020-11-06 17:43:19.473861256 +0100 *************** *** 464,470 **** // First char of a popup window may go on top of the right half of a // double-wide character. Clear the left half to avoid it getting the popup // window background color. ! if (coloff > 0 && ScreenLines[off_to] == 0 && ScreenLinesUC[off_to - 1] != 0 && (*mb_char2cells)(ScreenLinesUC[off_to - 1]) > 1) { --- 464,471 ---- // First char of a popup window may go on top of the right half of a // double-wide character. Clear the left half to avoid it getting the popup // window background color. ! if (coloff > 0 && enc_utf8 ! && ScreenLines[off_to] == 0 && ScreenLinesUC[off_to - 1] != 0 && (*mb_char2cells)(ScreenLinesUC[off_to - 1]) > 1) { *** ../vim-8.2.1962/src/terminal.c 2020-11-05 19:36:34.710317015 +0100 --- src/terminal.c 2020-11-06 17:53:19.560423185 +0100 *************** *** 1830,1835 **** --- 1830,1839 ---- width = cell.width; cell2cellattr(&cell, &p[pos.col]); + if (width == 2) + // second cell of double-width character has the + // same attributes. + p[pos.col + 1] = p[pos.col]; // Each character can be up to 6 bytes. if (ga_grow(&ga, VTERM_MAX_CHARS_PER_CELL * 6) == OK) *************** *** 3639,3644 **** --- 3643,3649 ---- } #endif else + // This will only store the lower byte of "c". ScreenLines[off] = c; } ScreenAttrs[off] = cell2attr(term, wp, cell.attrs, cell.fg, cell.bg); *************** *** 3647,3659 **** ++off; if (cell.width == 2) { - if (enc_utf8) - ScreenLinesUC[off] = NUL; - // don't set the second byte to NUL for a DBCS encoding, it // has been set above ! if (enc_utf8 || !has_mbyte) ScreenLines[off] = NUL; ++pos->col; ++off; --- 3652,3671 ---- ++off; if (cell.width == 2) { // don't set the second byte to NUL for a DBCS encoding, it // has been set above ! if (enc_utf8) ! { ! ScreenLinesUC[off] = NUL; ScreenLines[off] = NUL; + } + else if (!has_mbyte) + { + // Can't show a double-width character with a single-byte + // 'encoding', just use a space. + ScreenLines[off] = ' '; + ScreenAttrs[off] = ScreenAttrs[off - 1]; + } ++pos->col; ++off; *** ../vim-8.2.1962/src/testdir/test_popupwin.vim 2020-10-22 13:44:49.922509593 +0200 --- src/testdir/test_popupwin.vim 2020-11-06 17:34:31.211066268 +0100 *************** *** 3685,3690 **** --- 3685,3712 ---- call delete('XtestPopupThreeErrors') endfunc + func Test_popupwin_latin1_encoding() + CheckScreendump + CheckUnix + + " When 'encoding' is a single-byte encoding a terminal window will mess up + " the display. Check that showing a popup on top of that doesn't crash. + let lines =<< trim END + set encoding=latin1 + terminal cat Xmultibyte + call popup_create(['one', 'two', 'three', 'four'], #{line: 1, col: 10}) + END + call writefile(lines, 'XtestPopupLatin') + call writefile([repeat("\u3042 ", 120)], 'Xmultibyte') + + let buf = RunVimInTerminal('-S XtestPopupLatin', #{rows: 10}) + + call term_sendkeys(buf, ":q\") + call StopVimInTerminal(buf) + call delete('XtestPopupLatin') + call delete('Xmultibyte') + endfunc + func Test_popupwin_atcursor_far_right() new *** ../vim-8.2.1962/src/version.c 2020-11-06 13:44:16.731277020 +0100 --- src/version.c 2020-11-06 14:20:41.205250669 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1963, /**/ -- hundred-and-one symptoms of being an internet addict: 208. Your goals for the future are obtaining a second Gbit connection and upgrade your NAS to all SSD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///