From 62c5c4757c6886f7d3e5a0d3ca3d10e57b9e4c1a Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Wed, 24 May 2023 21:52:50 +0300 Subject: [PATCH] Fix comparing pointers and integers See #189 --- src/interpreter.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/interpreter.cc b/src/interpreter.cc index 59534ec..caac822 100644 --- a/src/interpreter.cc +++ b/src/interpreter.cc @@ -932,7 +932,7 @@ static void opConditionalOperatorNotEqual(Program* program) result = value[1].integerValue != value[0].integerValue; break; case VALUE_TYPE_PTR: - result = (intptr_t)(value[1].integerValue) != (intptr_t)(value[0].pointerValue); + result = (uintptr_t)(value[1].integerValue) != (uintptr_t)(value[0].pointerValue); break; default: assert(false && "Should be unreachable"); @@ -941,7 +941,7 @@ static void opConditionalOperatorNotEqual(Program* program) case VALUE_TYPE_PTR: switch (value[0].opcode) { case VALUE_TYPE_INT: - result = (intptr_t)(value[1].pointerValue) != (intptr_t)(value[0].integerValue); + result = (uintptr_t)(value[1].pointerValue) != (uintptr_t)(value[0].integerValue); break; case VALUE_TYPE_PTR: result = value[1].pointerValue != value[0].pointerValue; @@ -1028,7 +1028,7 @@ static void opConditionalOperatorEqual(Program* program) result = value[1].integerValue == value[0].integerValue; break; case VALUE_TYPE_PTR: - result = (intptr_t)(value[1].integerValue) == (intptr_t)(value[0].pointerValue); + result = (uintptr_t)(value[1].integerValue) == (uintptr_t)(value[0].pointerValue); break; default: assert(false && "Should be unreachable"); @@ -1037,7 +1037,7 @@ static void opConditionalOperatorEqual(Program* program) case VALUE_TYPE_PTR: switch (value[0].opcode) { case VALUE_TYPE_INT: - result = (intptr_t)(value[1].pointerValue) == (intptr_t)(value[0].integerValue); + result = (uintptr_t)(value[1].pointerValue) == (uintptr_t)(value[0].integerValue); break; case VALUE_TYPE_PTR: result = value[1].pointerValue == value[0].pointerValue; @@ -1131,7 +1131,7 @@ static void opConditionalOperatorLessThanEquals(Program* program) case VALUE_TYPE_PTR: switch (value[0].opcode) { case VALUE_TYPE_INT: - result = (intptr_t)value[1].pointerValue <= (intptr_t)value[0].integerValue; + result = (uintptr_t)value[1].pointerValue <= (uintptr_t)value[0].integerValue; break; default: assert(false && "Should be unreachable"); @@ -1385,7 +1385,7 @@ static void opConditionalOperatorGreaterThan(Program* program) case VALUE_TYPE_PTR: switch (value[0].opcode) { case VALUE_TYPE_INT: - result = (intptr_t)value[1].pointerValue > (intptr_t)value[0].integerValue; + result = (uintptr_t)value[1].pointerValue > (uintptr_t)value[0].integerValue; break; default: assert(false && "Should be unreachable");