From 16f4ab7787ae4bf8f61cc7cbeb73251f46709a55 Mon Sep 17 00:00:00 2001 From: Jo Date: Tue, 16 Jan 2024 20:42:32 +0800 Subject: [PATCH] Improve pointer comparsion for Nevada and Sonora mods (#291) --- src/interpreter.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/interpreter.cc b/src/interpreter.cc index a147ce8..3e3cc4e 100644 --- a/src/interpreter.cc +++ b/src/interpreter.cc @@ -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");