Function rand() returns random number from compile time seed, unless
srand() was called. So the fallback rand() cause that mkstemp() in fallback
code path always starts with the same directory name. Improve this fallback
code path and XOR the rand() number with the current time.
---
 mingw-w64-crt/misc/mkstemp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mingw-w64-crt/misc/mkstemp.c b/mingw-w64-crt/misc/mkstemp.c
index 7291efcc811b..b42df3cb65f8 100644
--- a/mingw-w64-crt/misc/mkstemp.c
+++ b/mingw-w64-crt/misc/mkstemp.c
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <io.h>
 #include <errno.h>
+#include <time.h>
 #include <share.h>
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -46,7 +47,7 @@ int __cdecl mkstemp (char *template_name)
     for (i = 0; i <= INT_MAX; i++) {
         for(j = index; j < len; j++) {
             if (rand_s(&r))
-                r = rand();
+                r = rand() ^ _time32(NULL);
             template_name[j] = letters[r % 62];
         }
         fd = _sopen(template_name,
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to