From 503d8818f5a2752e1598a4dfcc2cfa8b33d95fe0 Mon Sep 17 00:00:00 2001 From: halx99 Date: Tue, 9 Nov 2021 14:40:00 +0800 Subject: [PATCH] Use explicit type to compare integer --- cocos/base/CCValue.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cocos/base/CCValue.cpp b/cocos/base/CCValue.cpp index 4d04521289..1bfe95ff17 100644 --- a/cocos/base/CCValue.cpp +++ b/cocos/base/CCValue.cpp @@ -386,11 +386,16 @@ bool Value::operator==(const Value& v) const return false; if (this->isNull()) return true; - switch (getTypeFamily()) + switch (getType()) { - case Type::INTEGER: - return 0 == - memcmp(&_field.int64Val, &v._field.int64Val, ((uint32_t)_type & (uint32_t)Type::MASK_64BIT) ? sizeof(int64_t) : sizeof(int)); + case Type::INT_I32: + return v._field.intVal == this->_field.intVal; + case Type::INT_UI32: + return v._field.uintVal == this->_field.uintVal; + case Type::INT_I64: + return v._field.int64Val == this->_field.int64Val; + case Type::INT_UI64: + return v._field.int64Val == this->_field.int64Val; case Type::BOOLEAN: return v._field.boolVal == this->_field.boolVal; case Type::STRING: