From b0e9c0d7407d0c2e01481d39de8abb1f29a01c47 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 2 Jul 2024 09:39:36 +0200 Subject: [PATCH] QVersionNumber: add missing size check for comparesEqual() The whole point of separating comparesEqual() and compareThreeWay() is that the former can fail faster than the latter. To wit: segmentCount() is an inline operation and, for the common case of SSO storage, a single byte read. compare(), OTOH, is an out-of-line call. So compare the segmentCount() before calling compare(). Amends ecb0878cbc3bc677d0f440950d2d1e304bcea495. Change-Id: I3e46e73d4b8827532cc16428ca5e7f25bfa8608e Reviewed-by: Ivan Solovev (cherry picked from commit 9bd3d39b3fe2d760b9c484663bdc6c863a68e22e) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qversionnumber.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index e7ae107226c..c5ae1df1efc 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -360,7 +360,7 @@ private: [[nodiscard]] friend bool comparesEqual(const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept { - return compare(lhs, rhs) == 0; + return lhs.segmentCount() == rhs.segmentCount() && compare(lhs, rhs) == 0; } [[nodiscard]] friend Qt::strong_ordering compareThreeWay(const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept