]> granicus.if.org Git - vim/commitdiff
patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file v8.2.2055
authorBram Moolenaar <Bram@vim.org>
Thu, 26 Nov 2020 18:47:28 +0000 (19:47 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 26 Nov 2020 18:47:28 +0000 (19:47 +0100)
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)

src/fileio.c
src/version.c

index 27e9aaecf28b062ae4578f23ba9191fac7714d56..66061680b08ed4d3faae638903780fb20dfe0f95 100644 (file)
@@ -5167,17 +5167,24 @@ 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.
+
+    // 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)
        return NULL;
     if (!keep)
index 7b7bea9ee2aca0cdabff1852d9dd698f0aa08bb3..8c4c3fa665ceefaaad1fe3c00992a799f94c0f7b 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2055,
 /**/
     2054,
 /**/