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>
This commit is contained in:
Marc Mutz 2019-07-23 08:21:28 +03:00
parent 0ce3f7d62b
commit 6bc7309135

View File

@ -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) {