From ddb70bee2fd323ddc4273aec5d40d975f50d2904 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 22 Mar 2012 09:32:03 +0000 Subject: Stop relying on qHash always giving the same results The implementation of the various qHash overloads offered by Qt can change at any time for any reason (speed, quality, security, ...). Therefore, relying on the fact that qHash will always give an identical result across Qt versions (... across different processes, etc.), given identical input, is wrong. Note that this also implies that one cannot rely on QHash having a stable ordering (even without the random qHash seed). For such use cases, one must use f.i. a private hash function that will never change outside his own control. This patch adds a private hash function for QStrings, which is identical to the Qt(4) qHash(QString) implementation. A couple of spots in Qt where the results of a qHash call were actually saved on disk are ported to use the new function, and a bit of documentation is added to QHash docs. Change-Id: Ia3731ea26ac68649b535b95e9f36fbec3df693c8 Reviewed-by: Thiago Macieira Reviewed-by: Robin Burchell --- src/corelib/io/qresource.cpp | 2 +- src/corelib/io/qtldurl.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index fb3a24b940..4a0211c00a 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -673,7 +673,7 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const qDebug() << " " << child+j << " :: " << name(child+j); } #endif - const uint h = qHash(segment); + const uint h = qt_hash(segment.toString()); //do the binary search for the hash int l = 0, r = child_count-1; diff --git a/src/corelib/io/qtldurl.cpp b/src/corelib/io/qtldurl.cpp index 48df01b48c..efd663b09a 100644 --- a/src/corelib/io/qtldurl.cpp +++ b/src/corelib/io/qtldurl.cpp @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE static bool containsTLDEntry(const QString &entry) { - int index = qHash(entry) % tldCount; + int index = qt_hash(entry) % tldCount; int currentDomainIndex = tldIndices[index]; while (currentDomainIndex < tldIndices[index+1]) { QString currentEntry = QString::fromUtf8(tldData + currentDomainIndex); -- cgit v1.2.3