From 249595c63772f792081113e7605f26404a728943 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 15 Aug 2024 23:50:47 +0900 Subject: [PATCH] runtimes/native: Stop assuming little endian in tracef Fixes: https://github.com/aduros/wasm4/issues/752 --- runtimes/native/src/runtime.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/runtimes/native/src/runtime.c b/runtimes/native/src/runtime.c index e710f9e6..a7612c61 100644 --- a/runtimes/native/src/runtime.c +++ b/runtimes/native/src/runtime.c @@ -1,5 +1,6 @@ #include "runtime.h" +#include #include #include #include @@ -240,22 +241,22 @@ void w4_runtimeTracef (const uint8_t* str, const void* stack) { break; case 'c': bounds_check(argPtr, 4); - putc(*(char*)argPtr, stdout); + putc((char)w4_read32LE(argPtr), stdout); argPtr += 4; break; case 'd': bounds_check(argPtr, 4); - printf("%d", *(int32_t*)argPtr); + printf("%" PRId32, w4_read32LE(argPtr)); argPtr += 4; break; case 'x': bounds_check(argPtr, 4); - printf("%x", *(uint32_t*)argPtr); + printf("%" PRIx32, w4_read32LE(argPtr)); argPtr += 4; break; case 's': bounds_check(argPtr, 4); - strPtr = *(uint32_t*)argPtr; + strPtr = w4_read32LE(argPtr); argPtr += 4; const char *strPtr_host = (const char *)memory + strPtr; bounds_check_cstr(strPtr_host); @@ -263,7 +264,7 @@ void w4_runtimeTracef (const uint8_t* str, const void* stack) { break; case 'f': bounds_check(argPtr, 8); - printf("%lg", *(double*)argPtr); + printf("%lg", w4_readf64LE(argPtr)); argPtr += 8; break; default: