diff options
author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2024-05-08 08:17:16 +0300 |
---|---|---|
committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2024-05-08 08:17:16 +0300 |
commit | 86c62c8f6088ec148512457cb7e964661ba643b0 (patch) | |
tree | 15f82dc1436a5dd229fed729e15afb18bfafde62 /src/corelib/tools/qcryptographichash.cpp | |
parent | 4e158f6bfa7d0747d8da70b3b15a44b52e35bb8a (diff) | |
parent | 5ca8cfaa56043163997be2a6188812a8cd1c289c (diff) |
Merge remote-tracking branch 'origin/tqtc/lts-5.15.14' into tqtc/lts-5.15-opensourcev5.15.14-lts-lgpl5.15
Change-Id: Ibe29c3c6b47675d0a342bff3db91e79a3ea8a166
Diffstat (limited to 'src/corelib/tools/qcryptographichash.cpp')
-rw-r--r-- | src/corelib/tools/qcryptographichash.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index fa8d21e07a..b46bbeb41e 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -40,6 +40,8 @@ #include <qcryptographichash.h> #include <qiodevice.h> +#include <qmutex.h> +#include <private/qlocking_p.h> #include "../../3rdparty/sha1/sha1.cpp" @@ -192,6 +194,8 @@ public: }; void sha3Finish(int bitCount, Sha3Variant sha3Variant); #endif + // protects result in result() + QMutex finalizeMutex; QByteArray result; }; @@ -448,6 +452,9 @@ bool QCryptographicHash::addData(QIODevice* device) */ QByteArray QCryptographicHash::result() const { + // result() is a const function, so concurrent calls are allowed; protect: + const auto lock = qt_scoped_lock(d->finalizeMutex); + // check that no other thread already finalized before us: if (!d->result.isEmpty()) return d->result; @@ -535,6 +542,7 @@ QByteArray QCryptographicHash::result() const } #endif } + return d->result; } |