changeset 8730:c1ac169ee618 v7.4.1654

commit https://github.com/vim/vim/commit/52c6eaffd43a8c8865f8d6ed7cde0a8b137479e2 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Mar 25 18:42:46 2016 +0100 patch 7.4.1654 Problem: Crash when using expand('%:S') in a buffer without a name. Solution: Don't set a NUL. (James McCoy, closes https://github.com/vim/vim/issues/714)
author Christian Brabandt <cb@256bit.org>
date Fri, 25 Mar 2016 18:45:05 +0100
parents 663adb8f6065
children 36d95f21f340
files src/eval.c src/testdir/test_fnamemodify.vim src/version.c
diffstat 3 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -26439,9 +26439,11 @@ repeat:
     {
 	/* vim_strsave_shellescape() needs a NUL terminated string. */
 	c = (*fnamep)[*fnamelen];
-	(*fnamep)[*fnamelen] = NUL;
+	if (c != NUL)
+	    (*fnamep)[*fnamelen] = NUL;
 	p = vim_strsave_shellescape(*fnamep, FALSE, FALSE);
-	(*fnamep)[*fnamelen] = c;
+	if (c != NUL)
+	    (*fnamep)[*fnamelen] = c;
 	if (p == NULL)
 	    return -1;
 	vim_free(*bufp);
--- a/src/testdir/test_fnamemodify.vim
+++ b/src/testdir/test_fnamemodify.vim
@@ -41,3 +41,9 @@ func Test_fnamemodify()
   call assert_equal("'abc\\\ndef'",  fnamemodify("abc\ndef", ':S'))
   set shell&
 endfunc
+
+func Test_expand()
+  new
+  call assert_equal("",  expand('%:S'))
+  quit
+endfunc
--- a/src/version.c
+++ b/src/version.c
@@ -749,6 +749,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1654,
+/**/
     1653,
 /**/
     1652,