summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qtemporaryfile.cpp7
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp4
2 files changed, 5 insertions, 6 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index 8a99873fee..efab2a30ff 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -42,6 +42,7 @@
#ifndef QT_NO_TEMPORARYFILE
#include "qplatformdefs.h"
+#include "qrandom.h"
#include "private/qtemporaryfile_p.h"
#include "private/qfile_p.h"
#include "private/qsystemerror_p.h"
@@ -131,15 +132,17 @@ static bool createFileFromTemplate(NativeFileHandle &file,
Char *rIter = placeholderEnd;
#if defined(QT_BUILD_CORE_LIB)
+ // don't consume more than half of the template with the PID
+ Char *pidStart = placeholderEnd - (placeholderEnd - placeholderStart) / 2;
quint64 pid = quint64(QCoreApplication::applicationPid());
do {
*--rIter = Latin1Char((pid % 10) + '0');
pid /= 10;
- } while (rIter != placeholderStart && pid != 0);
+ } while (rIter != pidStart && pid != 0);
#endif
while (rIter != placeholderStart) {
- char ch = char((qrand() & 0xffff) % (26 + 26));
+ char ch = char(QRandomGenerator::bounded(26 + 26));
if (ch < 26)
*--rIter = Latin1Char(ch + 'A');
else
diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
index 59cd3a8411..17bcde4992 100644
--- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -866,8 +866,6 @@ void tst_QTemporaryFile::guaranteeUnique()
// First pass. See which filename QTemporaryFile will try first.
{
- // Fix the random seed.
- qsrand(1135);
QTemporaryFile tmpFile("testFile1.XXXXXX");
tmpFile.open();
takenFileName = tmpFile.fileName();
@@ -881,8 +879,6 @@ void tst_QTemporaryFile::guaranteeUnique()
// Second pass, now we have blocked its first attempt with a directory.
{
- // Fix the random seed.
- qsrand(1135);
QTemporaryFile tmpFile("testFile1.XXXXXX");
QVERIFY(tmpFile.open());
QString uniqueFileName = tmpFile.fileName();