Skip to content

Commit 52c6eaf

Browse files
committed
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 #714)
1 parent da64ab3 commit 52c6eaf

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/eval.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26439,9 +26439,11 @@ modify_fname(
2643926439
{
2644026440
/* vim_strsave_shellescape() needs a NUL terminated string. */
2644126441
c = (*fnamep)[*fnamelen];
26442-
(*fnamep)[*fnamelen] = NUL;
26442+
if (c != NUL)
26443+
(*fnamep)[*fnamelen] = NUL;
2644326444
p = vim_strsave_shellescape(*fnamep, FALSE, FALSE);
26444-
(*fnamep)[*fnamelen] = c;
26445+
if (c != NUL)
26446+
(*fnamep)[*fnamelen] = c;
2644526447
if (p == NULL)
2644626448
return -1;
2644726449
vim_free(*bufp);

src/testdir/test_fnamemodify.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,9 @@ func Test_fnamemodify()
4141
call assert_equal("'abc\\\ndef'", fnamemodify("abc\ndef", ':S'))
4242
set shell&
4343
endfunc
44+
45+
func Test_expand()
46+
new
47+
call assert_equal("", expand('%:S'))
48+
quit
49+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,8 @@ static char *(features[]) =
748748

749749
static int included_patches[] =
750750
{ /* Add new patch number below this line */
751+
/**/
752+
1654,
751753
/**/
752754
1653,
753755
/**/

0 commit comments

Comments
 (0)