diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-10-20 23:08:11 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-10-20 23:08:11 +0100 |
commit | d68a0044858d00de6100def1e389a3a9c1cdbcdc (patch) | |
tree | 8e87a146d0ee465a0cc97a519fd9b097539cd1ed /src | |
parent | 1d30fde3c989a962e0e1af4cbcf90e1ea483f1f4 (diff) | |
download | vim-git-d68a0044858d00de6100def1e389a3a9c1cdbcdc.tar.gz |
patch 8.2.3548: GTK GUI crashen when reading from stdinv8.2.3548
Problem: GTK GUI crashen when reading from stdin.
Solution: Do not overwrite the NUL after the string. (closes #9028)
Diffstat (limited to 'src')
-rw-r--r-- | src/gui_gtk_x11.c | 12 | ||||
-rw-r--r-- | src/testdir/test_gui.vim | 22 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 32 insertions, 4 deletions
diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c index e107c5e06..d46f81907 100644 --- a/src/gui_gtk_x11.c +++ b/src/gui_gtk_x11.c @@ -5744,12 +5744,16 @@ gui_gtk2_draw_string(int row, int col, char_u *s, int len, int flags) } } - // 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; diff --git a/src/testdir/test_gui.vim b/src/testdir/test_gui.vim index 84836e669..133298db3 100644 --- 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 diff --git a/src/version.c b/src/version.c index 3f80877da..1e7fb75ca 100644 --- a/src/version.c +++ b/src/version.c @@ -758,6 +758,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3548, +/**/ 3547, /**/ 3546, |