From cd4dba87fa52b5a3cad819ccf4161be5a6bd1d8b Mon Sep 17 00:00:00 2001 From: Mahmoud Mandour Date: Mon, 8 Nov 2021 22:29:36 +0200 Subject: [PATCH] LibSQL: Avoid signed arithmetic in `IntegerImpl::compare` --- Userland/Libraries/LibSQL/Value.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibSQL/Value.cpp b/Userland/Libraries/LibSQL/Value.cpp index 6553a945c7..80ddeea19e 100644 --- a/Userland/Libraries/LibSQL/Value.cpp +++ b/Userland/Libraries/LibSQL/Value.cpp @@ -704,10 +704,13 @@ bool IntegerImpl::can_cast(Value const& other_value) int IntegerImpl::compare(Value const& other) const { auto casted = other.to_int(); - if (!casted.has_value()) { + if (!casted.has_value()) return 1; - } - return value() - casted.value(); + + if (value() == casted.value()) + return 0; + + return value() < casted.value() ? -1 : 1; } u32 IntegerImpl::hash() const