Mercurial > vim
changeset 26028:be2d004247e1 v8.2.3548
patch 8.2.3548: GTK GUI crashen when reading from stdin
Commit: https://github.com/vim/vim/commit/d68a0044858d00de6100def1e389a3a9c1cdbcdc
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Oct 20 23:08:11 2021 +0100
patch 8.2.3548: GTK GUI crashen when reading from stdin
Problem: GTK GUI crashen when reading from stdin.
Solution: Do not overwrite the NUL after the string. (closes https://github.com/vim/vim/issues/9028)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 21 Oct 2021 00:15:03 +0200 |
parents | 988f7d88aacb |
children | 45c100bddf61 |
files | src/gui_gtk_x11.c src/testdir/test_gui.vim src/version.c |
diffstat | 3 files changed, 32 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gui_gtk_x11.c +++ b/src/gui_gtk_x11.c @@ -5744,12 +5744,16 @@ gui_gtk2_draw_string(int row, int col, c } } - // temporarily zero terminate substring, print, restore char, wrap - backup_ch = *(cs + slen); - *(cs + slen) = 0; + if (slen < len) + { + // temporarily zero terminate substring, print, restore char, wrap + backup_ch = *(cs + slen); + *(cs + slen) = NUL; + } len_sum += gui_gtk2_draw_string_ext(row, col + len_sum, cs, slen, flags, needs_pango); - *(cs + slen) = backup_ch; + if (slen < len) + *(cs + slen) = backup_ch; cs += slen; byte_sum += slen; needs_pango = should_need_pango;
--- a/src/testdir/test_gui.vim +++ b/src/testdir/test_gui.vim @@ -145,6 +145,28 @@ func Test_quoteplus() let @+ = quoteplus_saved endfunc +func Test_gui_read_stdin() + CheckUnix + + call writefile(['some', 'lines'], 'Xstdin') + let script =<< trim END + call writefile(getline(1, '$'), 'XstdinOK') + qa! + END + call writefile(script, 'Xscript') + + " Cannot use --not-a-term here, the "reading from stdin" message would not be + " displayed. + let vimcmd = substitute(GetVimCommand(), '--not-a-term', '', '') + + call system('cat Xstdin | ' .. vimcmd .. ' -f -g -S Xscript -') + call assert_equal(['some', 'lines'], readfile('XstdinOK')) + + call delete('Xstdin') + call delete('XstdinOK') + call delete('Xscript') +endfunc + func Test_set_background() let background_saved = &background