Patch 8.1.2234

9 views
Skip to first unread message

Bram Moolenaar

unread,
Oct 29, 2019, 11:13:17 PM10/29/19
to vim...@googlegroups.com

Patch 8.1.2234
Problem: get_short_pathname() fails depending on encoding.
Solution: Use the wide version of the library function. (closes #5129)
Files: src/filepath.c, src/testdir/test_shortpathname.vim


*** ../vim-8.1.2233/src/filepath.c 2019-10-08 23:26:46.746003980 +0200
--- src/filepath.c 2019-10-30 04:05:54.570956802 +0100
***************
*** 30,55 ****
get_short_pathname(char_u **fnamep, char_u **bufp, int *fnamelen)
{
int l, len;
! char_u *newbuf;

! len = *fnamelen;
! l = GetShortPathName((LPSTR)*fnamep, (LPSTR)*fnamep, len);
if (l > len - 1)
{
// If that doesn't work (not enough space), then save the string
// and try again with a new buffer big enough.
! newbuf = vim_strnsave(*fnamep, l);
if (newbuf == NULL)
return FAIL;
!
! vim_free(*bufp);
! *fnamep = *bufp = newbuf;
!
// Really should always succeed, as the buffer is big enough.
! l = GetShortPathName((LPSTR)*fnamep, (LPSTR)*fnamep, l+1);
}

! *fnamelen = l;
return OK;
}

--- 30,85 ----
get_short_pathname(char_u **fnamep, char_u **bufp, int *fnamelen)
{
int l, len;
! WCHAR *newbuf;
! WCHAR *wfname;

! len = MAXPATHL;
! newbuf = malloc(len * sizeof(*newbuf));
! if (newbuf == NULL)
! return FAIL;
!
! wfname = enc_to_utf16(*fnamep, NULL);
! if (wfname == NULL)
! {
! vim_free(newbuf);
! return FAIL;
! }
!
! l = GetShortPathNameW(wfname, newbuf, len);
if (l > len - 1)
{
// If that doesn't work (not enough space), then save the string
// and try again with a new buffer big enough.
! WCHAR *newbuf_t = newbuf;
! newbuf = vim_realloc(newbuf, (l + 1) * sizeof(*newbuf));
if (newbuf == NULL)
+ {
+ vim_free(wfname);
+ vim_free(newbuf_t);
return FAIL;
! }
// Really should always succeed, as the buffer is big enough.
! l = GetShortPathNameW(wfname, newbuf, l+1);
! }
! if (l != 0)
! {
! char_u *p = utf16_to_enc(newbuf, NULL);
! if (p != NULL)
! {
! vim_free(*bufp);
! *fnamep = *bufp = p;
! }
! else
! {
! vim_free(wfname);
! vim_free(newbuf);
! return FAIL;
! }
}
+ vim_free(wfname);
+ vim_free(newbuf);

! *fnamelen = l == 0 ? l : STRLEN(*bufp);
return OK;
}

*** ../vim-8.1.2233/src/testdir/test_shortpathname.vim 2019-08-08 21:52:35.518263963 +0200
--- src/testdir/test_shortpathname.vim 2019-10-30 04:05:54.570956802 +0100
***************
*** 1,6 ****
--- 1,9 ----
" Test for shortpathname ':8' extension.
" Only for use on Win32 systems!

+ set encoding=utf-8
+ scriptencoding utf-8
+
source check.vim
CheckMSWindows

***************
*** 67,69 ****
--- 70,89 ----

exe "cd " . save_dir
endfunc
+
+ func Test_ColonEight_MultiByte()
+ let dir = 'Xtest'
+
+ let file = dir . '/日本語のファイル.txt'
+
+ call mkdir(dir)
+ call writefile([], file)
+
+ let sfile = fnamemodify(file, ':8')
+
+ call assert_notequal(file, sfile)
+ call assert_match('\~', sfile)
+
+ call delete(file)
+ call delete(dir, 'd')
+ endfunc
*** ../vim-8.1.2233/src/version.c 2019-10-29 04:12:38.620582834 +0100
--- src/version.c 2019-10-30 04:08:20.542252427 +0100
***************
*** 743,744 ****
--- 743,746 ----
{ /* Add new patch number below this line */
+ /**/
+ 2234,
/**/

--
A)bort, R)etry, P)lease don't bother me again

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages