diff --git a/3rdparty/singleapplication/singleapplication.cpp b/3rdparty/singleapplication/singleapplication.cpp index bb524749..41048a61 100644 --- a/3rdparty/singleapplication/singleapplication.cpp +++ b/3rdparty/singleapplication/singleapplication.cpp @@ -40,9 +40,13 @@ #include #include #include -#include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +# include +#else +# include +#endif #include "singleapplication.h" #include "singleapplication_p.h" @@ -110,8 +114,12 @@ SingleApplication::SingleApplication(int &argc, char *argv[], bool allowSecondar d->memory->unlock(); // Random sleep here limits the probability of a collision between two racing apps +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + QThread::sleep(QRandomGenerator::global()->bounded(8u, 18u)); +#else qsrand(QDateTime::currentMSecsSinceEpoch() % std::numeric_limits::max()); - QThread::sleep(8 + static_cast (static_cast (qrand()) / RAND_MAX * 10)); + QThread::sleep(8 + static_cast(static_cast (qrand()) / RAND_MAX * 10)); +#endif } if (inst->primary == false) { diff --git a/3rdparty/singleapplication/singlecoreapplication.cpp b/3rdparty/singleapplication/singlecoreapplication.cpp index 13c1df9d..fcc7a605 100644 --- a/3rdparty/singleapplication/singlecoreapplication.cpp +++ b/3rdparty/singleapplication/singlecoreapplication.cpp @@ -40,9 +40,13 @@ #include #include #include -#include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +# include +#else +# include +#endif #include "singlecoreapplication.h" #include "singlecoreapplication_p.h" @@ -62,8 +66,7 @@ SingleCoreApplication::SingleCoreApplication(int &argc, char *argv[], bool allow // Store the current mode of the program d->options = options; - // Generating an application ID used for identifying the shared memory - // block and QLocalServer + // Generating an application ID used for identifying the shared memory block and QLocalServer d->genBlockServerName(); #ifdef Q_OS_UNIX @@ -111,8 +114,12 @@ SingleCoreApplication::SingleCoreApplication(int &argc, char *argv[], bool allow d->memory->unlock(); // Random sleep here limits the probability of a collision between two racing apps +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + QThread::sleep(QRandomGenerator::global()->bounded(8u, 18u)); +#else qsrand(QDateTime::currentMSecsSinceEpoch() % std::numeric_limits::max()); - QThread::sleep(8 + static_cast (static_cast (qrand()) / RAND_MAX * 10)); + QThread::sleep(8 + static_cast(static_cast (qrand()) / RAND_MAX * 10)); +#endif } if (inst->primary == false) { diff --git a/ext/libstrawberry-common/core/closure.cpp b/ext/libstrawberry-common/core/closure.cpp index 17db12f9..647cf2e9 100644 --- a/ext/libstrawberry-common/core/closure.cpp +++ b/ext/libstrawberry-common/core/closure.cpp @@ -19,6 +19,9 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +# include +#endif #include "closure.h" @@ -72,6 +75,13 @@ void DoAfter(QObject *receiver, const char *slot, int msec) { } void DoInAMinuteOrSo(QObject *receiver, const char *slot) { + +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + int msec = (60 + QRandomGenerator::global()->bounded(1, 60)) * kMsecPerSec; +#else int msec = (60 + (qrand() % 60)) * kMsecPerSec; +#endif + DoAfter(receiver, slot, msec); + } diff --git a/ext/libstrawberry-common/core/workerpool.h b/ext/libstrawberry-common/core/workerpool.h index b6a61c1a..e5b9600b 100644 --- a/ext/libstrawberry-common/core/workerpool.h +++ b/ext/libstrawberry-common/core/workerpool.h @@ -33,6 +33,9 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +# include +#endif #include "core/logging.h" @@ -264,7 +267,11 @@ void WorkerPool::StartOneWorker(Worker *worker) { // Create a server, find an unused name and start listening forever { +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + const int unique_number = QRandomGenerator::global()->bounded((int)(quint64(this) & 0xFFFFFFFF)); +#else const int unique_number = qrand() ^ ((int)(quint64(this) & 0xFFFFFFFF)); +#endif const QString name = QString("%1_%2").arg(local_server_name_).arg(unique_number); if (worker->local_server_->listen(name)) { diff --git a/ext/strawberry-tagreader/main.cpp b/ext/strawberry-tagreader/main.cpp index 1ecb4bba..e0fe7a8c 100644 --- a/ext/strawberry-tagreader/main.cpp +++ b/ext/strawberry-tagreader/main.cpp @@ -46,9 +46,11 @@ int main(int argc, char **argv) { } // Seed random number generator +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) timeval time; gettimeofday(&time, nullptr); qsrand((time.tv_sec * 1000) + (time.tv_usec / 1000)); +#endif logging::Init(); qLog(Info) << "TagReader worker connecting to" << args[1]; @@ -61,7 +63,9 @@ int main(int argc, char **argv) { return 1; } +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) QSslSocket::addDefaultCaCertificates(QSslCertificate::fromPath(":/certs/godaddy-root.pem", QSsl::Pem)); +#endif TagReaderWorker worker(&socket); diff --git a/ext/strawberry-tagreader/tagreaderworker.cpp b/ext/strawberry-tagreader/tagreaderworker.cpp index b058b5b7..55536198 100644 --- a/ext/strawberry-tagreader/tagreaderworker.cpp +++ b/ext/strawberry-tagreader/tagreaderworker.cpp @@ -35,14 +35,6 @@ void TagReaderWorker::MessageArrived(const pb::tagreader::Message& message) { pb::tagreader::Message reply; -#if 0 - // Crash every few requests - if (qrand() % 10 == 0) { - qLog(Debug) << "Crashing on request ID" << message.id(); - abort(); - } -#endif - if (message.has_read_file_request()) { tag_reader_.ReadFile(QStringFromStdString(message.read_file_request().filename()), reply.mutable_read_file_response()->mutable_metadata()); } diff --git a/src/core/utilities.cpp b/src/core/utilities.cpp index 22fe6192..97743af3 100644 --- a/src/core/utilities.cpp +++ b/src/core/utilities.cpp @@ -64,6 +64,9 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +# include +#endif #include @@ -540,7 +543,11 @@ bool IsMouseEventInWidget(const QMouseEvent *e, const QWidget *widget) { quint16 PickUnusedPort() { forever { +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + const quint64 port = QRandomGenerator::global()->bounded(49152, 65535); +#else const quint16 port = 49152 + qrand() % 16384; +#endif QTcpServer server; if (server.listen(QHostAddress::Any, port)) { @@ -821,8 +828,12 @@ QString CryptographicRandomString(const int len) { QString GetRandomString(const int len, const QString &UseCharacters) { QString randstr; - for(int i=0 ; i < len ; ++i) { - int index = qrand() % UseCharacters.length(); + for(int i = 0 ; i < len ; ++i) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + const int index = QRandomGenerator::global()->bounded(0, UseCharacters.length()); +#else + const int index = qrand() % UseCharacters.length(); +#endif QChar nextchar = UseCharacters.at(index); randstr.append(nextchar); } diff --git a/src/internet/localredirectserver.cpp b/src/internet/localredirectserver.cpp index c5ef6039..1e4cf1df 100644 --- a/src/internet/localredirectserver.cpp +++ b/src/internet/localredirectserver.cpp @@ -48,6 +48,9 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +# include +#endif LocalRedirectServer::LocalRedirectServer(QObject *parent) : QTcpServer(parent), @@ -152,7 +155,12 @@ bool LocalRedirectServer::GenerateCertificate() { return false; } +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + quint64 serial = 9999999 + QRandomGenerator::global()->bounded(1000000); +#else quint64 serial = (9999999 + qrand() % 1000000); +#endif + QByteArray q_serial; q_serial.setNum(serial);