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");