From 944c63e8ec8a2f935ed611345e95e1e55b49d994 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 20 Jul 2026 15:36:57 +0800 Subject: [PATCH] Common (Base64): unifies the code of endian testing --- src/common/impl/base64.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/impl/base64.c b/src/common/impl/base64.c index 98a415ffb..3f5ddf139 100644 --- a/src/common/impl/base64.c +++ b/src/common/impl/base64.c @@ -6,7 +6,13 @@ void ffBase64EncodeRaw(uint32_t size, const char* str, uint32_t* out_size, char* char* out = output; const char* ends = str + (size - size % 3); while (str != ends) { - uint32_t n = __builtin_bswap32(*(uint32_t*) str); + uint32_t n = *(uint32_t*) str; + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + // The 3 input bytes must be laid out big-endian (str[0] in the most + // significant position). On little-endian hosts swap; on big-endian + // hosts the word is already in the right order. + n = __builtin_bswap32(n); + #endif *out++ = chars[(n >> 26) & 63]; *out++ = chars[(n >> 20) & 63]; *out++ = chars[(n >> 14) & 63];