use qsrand/qrand for thread-safety

svn path=/trunk/kdesupport/qca/; revision=669694
This commit is contained in:
Justin Karneges 2007-05-30 04:55:35 +00:00
parent 89b1cd4de4
commit ad90fab80c

View File

@ -23,8 +23,6 @@
#include <QMutex> #include <QMutex>
#include <QHash> #include <QHash>
#include "qcaprovider.h" #include "qcaprovider.h"
#include <stdlib.h>
#include <time.h>
#ifndef QCA_NO_SYSTEMSTORE #ifndef QCA_NO_SYSTEMSTORE
# include "qca_systemstore.h" # include "qca_systemstore.h"
@ -89,7 +87,7 @@ public:
{ {
SecureArray buf(size); SecureArray buf(size);
for(int n = 0; n < (int)buf.size(); ++n) for(int n = 0; n < (int)buf.size(); ++n)
buf[n] = (char)rand(); buf[n] = (char)qrand();
return buf; return buf;
} }
}; };
@ -1081,11 +1079,11 @@ public:
virtual void init() virtual void init()
{ {
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
// avoid divide-by-zero
while(0 == now.time().msec()) uint t = now.toTime_t();
now = QDateTime::currentDateTime(); if(now.time().msec() > 0)
time_t t = now.toTime_t() / now.time().msec(); t /= now.time().msec();
srand(t); qsrand(t);
} }
virtual int version() const virtual int version() const