Improve pointer comparsion for Nevada and Sonora mods (#291)

This commit is contained in:
Jo 2024-01-16 20:42:32 +08:00 committed by GitHub
parent e23c4eddda
commit 16f4ab7787
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1131,7 +1131,12 @@ static void opConditionalOperatorLessThanEquals(Program* program)
case VALUE_TYPE_PTR:
switch (value[0].opcode) {
case VALUE_TYPE_INT:
result = (uintptr_t)value[1].pointerValue <= (uintptr_t)value[0].integerValue;
if (value[0].integerValue > 0) {
result = (uintptr_t)value[1].pointerValue <= (uintptr_t)value[0].integerValue;
} else {
// (ptr <= int{0 or negative}) means (ptr == nullptr)
result = nullptr == value[1].pointerValue;
}
break;
default:
assert(false && "Should be unreachable");
@ -1385,7 +1390,12 @@ static void opConditionalOperatorGreaterThan(Program* program)
case VALUE_TYPE_PTR:
switch (value[0].opcode) {
case VALUE_TYPE_INT:
result = (uintptr_t)value[1].pointerValue > (uintptr_t)value[0].integerValue;
if (value[0].integerValue > 0) {
result = (uintptr_t)value[1].pointerValue > (uintptr_t)value[0].integerValue;
} else {
// (ptr > int{0 or negative}) means (ptr != nullptr)
result = nullptr != value[1].pointerValue;
}
break;
default:
assert(false && "Should be unreachable");