summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-08-19 14:38:42 +0200
committerBram Moolenaar <Bram@vim.org>2018-08-19 14:38:42 +0200
commitcea1f9ec5256755ad119526fea2ef6811f7b53cd (patch)
treeaf3e1e22fd3c2e0f197e81357a16f4c3978ea3ad
parent111bbd61e96d1d3ee4bc07ae435fd97b88413aba (diff)
downloadvim-git-cea1f9ec5256755ad119526fea2ef6811f7b53cd.tar.gz
patch 8.1.0297: MS-Windows: tests fail, Vim crashesv8.1.0297
Problem: MS-Windows: tests fail, Vim crashes. Solution: Fix long file name handling.
-rw-r--r--src/os_win32.c21
-rw-r--r--src/version.c2
2 files changed, 18 insertions, 5 deletions
diff --git a/src/os_win32.c b/src/os_win32.c
index 8065ee858..dc98d6acd 100644
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -3109,6 +3109,7 @@ mch_dirname(
int len)
{
char_u abuf[_MAX_PATH + 1];
+ DWORD lfnlen;
/*
* Originally this was:
@@ -3124,11 +3125,19 @@ mch_dirname(
if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0)
{
WCHAR wcbuf[_MAX_PATH + 1];
- char_u *p;
+ char_u *p = NULL;
if (GetLongPathNameW(wbuf, wcbuf, _MAX_PATH) != 0)
+ {
p = utf16_to_enc(wcbuf, NULL);
- else
+ if (STRLEN(p) >= (size_t)len)
+ {
+ // long path name is too long, fall back to short one
+ vim_free(p);
+ p = NULL;
+ }
+ }
+ if (p == NULL)
p = utf16_to_enc(wbuf, NULL);
if (p != NULL)
@@ -3143,11 +3152,13 @@ mch_dirname(
#endif
if (GetCurrentDirectory(len, (LPSTR)buf) == 0)
return FAIL;
- if (GetLongPathNameA((LPSTR)buf, (LPSTR)abuf, _MAX_PATH) == 0)
- // return the short path name
+ lfnlen = GetLongPathNameA((LPCSTR)buf, (LPSTR)abuf, _MAX_PATH);
+ if (lfnlen == 0 || lfnlen >= (DWORD)len)
+ // Failed to get long path name or it's too long: fall back to the
+ // short path name.
return OK;
- vim_strncpy(abuf, buf, len - 1);
+ STRCPY(buf, abuf);
return OK;
}
diff --git a/src/version.c b/src/version.c
index 194ee4cda..99f86e70c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -795,6 +795,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 297,
+/**/
296,
/**/
295,