diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2021-08-11 16:57:39 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2021-08-16 17:26:29 +0000 |
commit | db8368f5353494c36aae40d36a214877f5a93940 (patch) | |
tree | c69e882a424dda883b18fa4471f635546223218d | |
parent | 29cfea3e82e04345b2cbb07c3ebebebbe3ced0bb (diff) |
QMetaEnum: stop parsing when an invalid key is found
The old code obfuscated the algorithm by or'ing -1 into the return
value, which is equivalent to setting it to -1 on two's complement
architectures (which C++ these days requires), and happily continuing
to accumulate potential keys. But nothing that can be or'ed into -1
will ever change the value, so this is rather pointless, as we're not
emitting diagnostics apart from setting a bool to false.
Fix by simply returning -1. That makes it obvious what we're
returning, and we return early on error.
Pick-to: 6.2
Change-Id: I8957f44e03609ad58d6c25d5fa78c57190b14bdd
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r-- | src/corelib/kernel/qmetaobject.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index ee2bf156fe..6bac42162b 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -2872,7 +2872,7 @@ int QMetaEnum::keysToValue(const char *keys, bool *ok) const if (i < 0) { if (ok != nullptr) *ok = false; - value |= -1; + return -1; } } return value; |