Mercurial > vim
changeset 14567:7267c0d910fe v8.1.0297
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
commit https://github.com/vim/vim/commit/cea1f9ec5256755ad119526fea2ef6811f7b53cd
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 19 14:38:42 2018 +0200
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Problem: MS-Windows: tests fail, Vim crashes.
Solution: Fix long file name handling.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 19 Aug 2018 14:45:04 +0200 |
parents | 427c57b41bc2 |
children | e8225e90804f |
files | src/os_win32.c src/version.c |
diffstat | 2 files changed, 18 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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; }