From b4d13d060a7fb6d68b32820a71a39dadfe5e2678 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Thu, 4 Jul 2024 11:18:36 +0200 Subject: [PATCH] AK: Fix {:c} formatter for big-endian --- AK/Format.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/AK/Format.cpp b/AK/Format.cpp index f8083a5ff59..04efdb3b79c 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -888,7 +888,12 @@ ErrorOr Formatter::format(FormatBuilder& builder, T value) m_mode = Mode::String; Formatter formatter { *this }; - return formatter.format(builder, StringView { reinterpret_cast(&value), 1 }); + + // convert value to single byte, important for big-endian because the LSB is the last byte. + VERIFY(value >= 0 && value <= 127); + char const c = (value & 0x7f); + + return formatter.format(builder, StringView { &c, 1 }); } if (m_precision.has_value())