diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-07-23 08:21:28 +0300 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-07-26 12:18:47 +0300 |
commit | 6bc7309135ea6fc6c5d881e988b560e09825059d (patch) | |
tree | 1a4caf91dfd6a8f6dadfaee29d15f39a22ac1567 /src/corelib/io/qresource.cpp | |
parent | 0ce3f7d62b93427ca5d0f4284ba774691cbbd4a7 (diff) | |
download | qtbase-6bc7309135ea6fc6c5d881e988b560e09825059d.tar.gz |
QResource: fix nullptr-check gone tautological
Amends 136c5b9338f71775eb42528cfc7c23b2b4e5dff9.
Before that change, each of the three members was a separate
Q_GLOBAL_STATIC, so checking resourceList() for nullptr was the
correct thing to do to find out whether the static was already
destroyed.
After the change, the resourceList() function will never return
nullptr. Either resourceGlobalData.isDestroyed(), in which case
dereferencing it asserts, or it isn't, in which case resourceList()
returns a valid pointer.
An explicit isDestroyed() check was added to the unregister function,
but the register one was also checking resourceList() for nullptr,
and this was left unprotected.
Add the check and remove the now-tautological checks for nullptr
resourceList().
Change-Id: I41fe66939ce858a77802b8af04c1de6e4fafe048
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/io/qresource.cpp')
-rw-r--r-- | src/corelib/io/qresource.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index 564a3e5f51..6c458da77a 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -852,8 +852,10 @@ bool QResourceRoot::mappingRootSubdir(const QString &path, QString *match) const Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree, const unsigned char *name, const unsigned char *data) { + if (resourceGlobalData.isDestroyed()) + return false; QMutexLocker lock(resourceMutex()); - if ((version == 0x01 || version == 0x2) && resourceList()) { + if (version == 0x01 || version == 0x2) { bool found = false; QResourceRoot res(version, tree, name, data); for(int i = 0; i < resourceList()->size(); ++i) { @@ -879,7 +881,7 @@ Q_CORE_EXPORT bool qUnregisterResourceData(int version, const unsigned char *tre return false; QMutexLocker lock(resourceMutex()); - if ((version == 0x01 || version == 0x02) && resourceList()) { + if (version == 0x01 || version == 0x02) { QResourceRoot res(version, tree, name, data); for(int i = 0; i < resourceList()->size(); ) { if(*resourceList()->at(i) == res) { |