Skip to content

Commit

Permalink
win32: Mitigate temp file name confliction
Browse files Browse the repository at this point in the history
  • Loading branch information
k-takata committed Nov 26, 2020
1 parent 1053ea3 commit ead7e66
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -5167,17 +5167,22 @@ vim_tempname(
# ifdef MSWIN
WCHAR wszTempFile[_MAX_PATH + 1];
WCHAR buf4[4];
WCHAR *chartab = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
char_u *retval;
char_u *p;
long i;

wcscpy(itmp, L"");
if (GetTempPathW(_MAX_PATH, wszTempFile) == 0)
{
wszTempFile[0] = L'.'; // GetTempPathW() failed, use current dir
wszTempFile[1] = NUL;
wszTempFile[1] = L'\\';
wszTempFile[2] = NUL;
}
wcscpy(buf4, L"VIM");
buf4[2] = extra_char; // make it "VIa", "VIb", etc.
i = mch_get_pid() + extra_char;
buf4[1] = chartab[i % 37]; // make it a bit random
buf4[2] = chartab[101 * i % 37];
if (GetTempFileNameW(wszTempFile, buf4, 0, itmp) == 0)
return NULL;
if (!keep)
Expand Down

0 comments on commit ead7e66

Please sign in to comment.