]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0891: MS-Windows: filename-modifier ":8:t" causes underflow v9.2.0891
authorHirohito Higashi <h.east.727@gmail.com>
Sat, 1 Aug 2026 13:26:21 +0000 (13:26 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 1 Aug 2026 13:26:21 +0000 (13:26 +0000)
Problem:  On MS-Windows using ":8" with ":t", ":e" or ":r" in one
          fnamemodify() gives a wrong result or an out of memory error.
Solution: Recompute the tail after ":8" replaced the name
          (Hirohito Higashi).

related: #20899
closes:  #20903

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/filepath.c
src/testdir/test_shortpathname.vim
src/version.c

index 8bdba335c662dc610252fbc575760e3caf80197e..e70b9c300b0b0a556ff6822d023c6a2dcf88853d 100644 (file)
@@ -586,6 +586,10 @@ repeat:
            }
            *fnamelen = l;
        }
+
+       // The name was replaced by the short name, "tail" points into the
+       // previous name.
+       tail = gettail(*fnamep);
     }
 #endif // MSWIN
 
index b3d7b82be50133361625b014026a05f1b921fabb..a1d9d9816ee7c317a542f71389d2d9a50bf1f4f5 100644 (file)
@@ -101,4 +101,24 @@ func Test_ColonEight_notexists()
   call assert_equal(non_exists, fnamemodify(non_exists, ':p:8'))
 endfunc
 
+" ":8" replaces the name, the modifiers after it must use the new name.
+func Test_ColonEight_then_tail()
+  let dir = 'c:/Xtest_C8tail'
+  call s:SetupDir(dir)
+
+  let file = dir . '/longfilename.txt'
+
+  call mkdir(dir, 'D')
+  call writefile([], file, 'D')
+
+  let sfile = fnamemodify(file, ':p:8')
+  if sfile ==? fnamemodify(file, ':p')
+    throw 'Skipped: 8.3 short names are not created on this volume'
+  endif
+
+  call assert_equal(fnamemodify(sfile, ':t'), fnamemodify(file, ':p:8:t'))
+  call assert_equal(fnamemodify(sfile, ':e'), fnamemodify(file, ':p:8:e'))
+  call assert_equal(fnamemodify(sfile, ':r'), fnamemodify(file, ':p:8:r'))
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 09996f74bd94388b7a85f5bff61ed49b912c4a84..c48aca0ff458e5c2de1fbd87d4b3514ce5befb75 100644 (file)
@@ -758,6 +758,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    891,
 /**/
     890,
 /**/