]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.3548: GTK GUI crashen when reading from stdin v8.2.3548
authorBram Moolenaar <Bram@vim.org>
Wed, 20 Oct 2021 22:08:11 +0000 (23:08 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 20 Oct 2021 22:08:11 +0000 (23:08 +0100)
Problem:    GTK GUI crashen when reading from stdin.
Solution:   Do not overwrite the NUL after the string. (closes #9028)

src/gui_gtk_x11.c
src/testdir/test_gui.vim
src/version.c

index e107c5e06080415e84684c3c2a33c64d41fef903..d46f8190739b5a934f1ca9a1ca6e1077ec815f32 100644 (file)
@@ -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;
index 84836e6692835fa0785fd05df713d82324576193..133298db3ae16120a1f94302043d58a4b4415e13 100644 (file)
@@ -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
 
index 3f80877da912146d475bbf56dbb85a4c2270749d..1e7fb75cab8b082bf14fc0974f18b6df1a07f3f0 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3548,
 /**/
     3547,
 /**/