Skip to content

Commit

Permalink
AK: Fix {:c} formatter for big-endian
Browse files Browse the repository at this point in the history
  • Loading branch information
sideeffect42 authored and Dennis Camera committed Jul 10, 2024
1 parent 648b36f commit 1ab5b5e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion AK/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,12 @@ ErrorOr<void> Formatter<T>::format(FormatBuilder& builder, T value)
m_mode = Mode::String;

Formatter<StringView> formatter { *this };
return formatter.format(builder, StringView { reinterpret_cast<char const*>(&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())
Expand Down

0 comments on commit 1ab5b5e

Please sign in to comment.