From 4d1d88aa16c9d2b50ac2af3d4f60e3f618d9252c Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 18 Jan 2024 17:53:46 +0330 Subject: [PATCH] AK: Make the :hex-dump format specifier print all characters Previously the final line would be skipped if it was not a multiple of |width|, this makes the character view show up for that line. --- AK/Format.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AK/Format.cpp b/AK/Format.cpp index 683aeadfc6..cc59e4bd3b 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -752,7 +752,7 @@ ErrorOr FormatBuilder::put_hexdump(ReadonlyBytes bytes, size_t width, char { auto put_char_view = [&](auto i) -> ErrorOr { TRY(put_padding(fill, 4)); - for (size_t j = i - width; j < i; ++j) { + for (size_t j = i - min(i, width); j < i; ++j) { auto ch = bytes[j]; TRY(m_builder.try_append(ch >= 32 && ch <= 127 ? ch : '.')); // silly hack } @@ -769,7 +769,7 @@ ErrorOr FormatBuilder::put_hexdump(ReadonlyBytes bytes, size_t width, char TRY(put_u64(bytes[i], 16, false, false, true, false, Align::Right, 2)); } - if (width > 0 && bytes.size() && bytes.size() % width == 0) + if (width > 0) TRY(put_char_view(bytes.size())); return {};