From 56593f419b2bf08e8b665b9efec504730cbb065b Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Mon, 8 Apr 2024 17:02:20 +0200 Subject: [PATCH] Fix `JS_ReadString` for wide strings on big endian targets (#354) swap words of wide character strings upon loading on a big endian target. --- quickjs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/quickjs.c b/quickjs.c index b35ed9f..a918691 100644 --- a/quickjs.c +++ b/quickjs.c @@ -33614,7 +33614,13 @@ static JSString *JS_ReadString(BCReaderState *s) } memcpy(p->u.str8, s->ptr, size); s->ptr += size; - if (!is_wide_char) { + if (is_wide_char) { + if (is_be()) { + uint32_t i; + for (i = 0; i < len; i++) + p->u.str16[i] = bswap16(p->u.str16[i]); + } + } else { p->u.str8[size] = '\0'; /* add the trailing zero for 8 bit strings */ } #ifdef DUMP_READ_OBJECT