Make sure that the random generator is initialized in all code paths
authorFrederik Gladhorn <frederik.gladhorn@digia.com>
Fri, 17 Jan 2014 10:04:41 +0000 (11:04 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 17 Jan 2014 12:47:08 +0000 (13:47 +0100)
Change-Id: Ice4826e7670cffa791250a95387ac1121ddc4089
Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
src/websockets/qwebsocket_p.cpp
src/websockets/qwebsocket_p.h

index 2b63860..7d6c7a9 100644 (file)
@@ -109,8 +109,7 @@ QWebSocketPrivate::QWebSocketPrivate(const QString &origin, QWebSocketProtocol::
     m_dataProcessor(),
     m_configuration()
 {
-    Q_ASSERT(pWebSocket);
-    qsrand(static_cast<uint>(QDateTime::currentMSecsSinceEpoch()));
+    init();
 }
 
 /*!
@@ -139,13 +138,22 @@ QWebSocketPrivate::QWebSocketPrivate(QTcpSocket *pTcpSocket, QWebSocketProtocol:
     m_dataProcessor(),
     m_configuration()
 {
-    Q_ASSERT(pWebSocket);
+    init();
     makeConnections(m_pSocket.data());
 }
 
 /*!
     \internal
 */
+void QWebSocketPrivate::init()
+{
+    Q_ASSERT(q_ptr);
+    qsrand(static_cast<uint>(QDateTime::currentMSecsSinceEpoch()));
+}
+
+/*!
+    \internal
+*/
 QWebSocketPrivate::~QWebSocketPrivate()
 {
     if (!m_pSocket)
index 68317ea..2786727 100644 (file)
@@ -107,6 +107,7 @@ public:
                                QObject *parent = Q_NULLPTR);
     virtual ~QWebSocketPrivate();
 
+    void init();
     void abort();
     QAbstractSocket::SocketError error() const;
     QString errorString() const;