From b367479d004dd36f6f8ca8d259e4bdee73da10a7 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 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/AK/Format.cpp b/AK/Format.cpp index b259684d97eed4..43b125cb172afd 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -879,13 +879,17 @@ template ErrorOr Formatter::format(FormatBuilder& builder, T value) { if (m_mode == Mode::Character) { - // FIXME: We just support ASCII for now, in the future maybe unicode? - // VERIFY(value >= 0 && value <= 127); - m_mode = Mode::String; Formatter formatter { *this }; - return formatter.format(builder, StringView { reinterpret_cast(&value), 1 }); + + // FIXME: We just support ASCII for now, in the future maybe unicode? + VERIFY(value >= 0 && value <= 127); + + // Convert value to a single byte. This is important for big-endian systems, because the LSB is stored in the last byte. + char const c = (value & 0x7f); + + return formatter.format(builder, StringView { &c, 1 }); } if (m_precision.has_value())