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>
This commit is contained in:
Marc Mutz 2021-08-11 16:57:39 +02:00
parent 29cfea3e82
commit db8368f535

View File

@ -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;