From 6fc4b67d0ef0362af35ea93dab4be4a2827f3d13 Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Sun, 7 Apr 2024 13:38:49 +0200 Subject: [PATCH] Fix `JS_ReadString` for wide strings on big endian targets --- quickjs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/quickjs.c b/quickjs.c index 49f319cd3..e728d53ff 100644 --- a/quickjs.c +++ b/quickjs.c @@ -33650,7 +33650,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