瀏覽代碼

LibSQL: Avoid signed arithmetic in `IntegerImpl::compare`

Mahmoud Mandour 3 年之前
父節點
當前提交
cd4dba87fa
共有 1 個文件被更改,包括 6 次插入3 次删除
  1. 6 3
      Userland/Libraries/LibSQL/Value.cpp

+ 6 - 3
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