0
0
mirror of https://github.com/vim/vim.git synced 2025-09-29 04:34:16 -04:00

patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file

Problem:    MS-Windows: two Vim instances may use the same temp file.
Solution:   Use the process ID for the temp name. (Ken Takata, closes #7378)
This commit is contained in:
Bram Moolenaar
2020-11-26 19:47:28 +01:00
parent d49a35a1c3
commit 2472a74be4
2 changed files with 11 additions and 2 deletions

View File

@@ -5167,17 +5167,24 @@ vim_tempname(
# ifdef MSWIN # ifdef MSWIN
WCHAR wszTempFile[_MAX_PATH + 1]; WCHAR wszTempFile[_MAX_PATH + 1];
WCHAR buf4[4]; WCHAR buf4[4];
WCHAR *chartab = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char_u *retval; char_u *retval;
char_u *p; char_u *p;
long i;
wcscpy(itmp, L""); wcscpy(itmp, L"");
if (GetTempPathW(_MAX_PATH, wszTempFile) == 0) if (GetTempPathW(_MAX_PATH, wszTempFile) == 0)
{ {
wszTempFile[0] = L'.'; // GetTempPathW() failed, use current dir wszTempFile[0] = L'.'; // GetTempPathW() failed, use current dir
wszTempFile[1] = NUL; wszTempFile[1] = L'\\';
wszTempFile[2] = NUL;
} }
wcscpy(buf4, L"VIM"); wcscpy(buf4, L"VIM");
buf4[2] = extra_char; // make it "VIa", "VIb", etc.
// randomize the name to avoid collisions
i = mch_get_pid() + extra_char;
buf4[1] = chartab[i % 36];
buf4[2] = chartab[101 * i % 36];
if (GetTempFileNameW(wszTempFile, buf4, 0, itmp) == 0) if (GetTempFileNameW(wszTempFile, buf4, 0, itmp) == 0)
return NULL; return NULL;
if (!keep) if (!keep)

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2055,
/**/ /**/
2054, 2054,
/**/ /**/