all repos — hex @ 4af9402ef3cb9afb9dc4b3a5ec73bce9474e730b

A tiny, minimalist, slightly-esoteric concatenative programming lannguage.

Fixes.
h3rald h3rald@h3rald.com
Wed, 18 Dec 2024 18:49:32 +0100
commit

4af9402ef3cb9afb9dc4b3a5ec73bce9474e730b

parent

d132857950d999194ef28cafb96ee7953e5df04e

1 files changed, 12 insertions(+), 1 deletions(-)

jump to
M src/vm.csrc/vm.c

@@ -698,7 +698,7 @@

int hex_interpret_bytecode_integer(hex_context_t *ctx, uint8_t **bytecode, size_t *size, hex_item_t *result) { size_t length = 0; - uint32_t value = 0; + int32_t value = 0; // Use signed 32-bit integer to handle negative values int shift = 0; // Decode the variable-length integer for the length

@@ -727,6 +727,17 @@ for (size_t i = 0; i < length; i++)

{ value |= (*bytecode)[i] << (8 * i); // Accumulate in little-endian order } + + // Handle sign extension for 32-bit value + if (length == 4) + { + // If the value is negative, we need to sign-extend it. + if (value & 0x80000000) + { // If the sign bit is set (negative value) + value |= 0xFF000000; // Sign-extend to 32 bits + } + } + *bytecode += length; *size -= length;