From 43885a76e40007a195dcb83566825d896449795b Mon Sep 17 00:00:00 2001 From: mierenhoop <46939409+mierenhoop@users.noreply.github.com> Date: Tue, 26 Mar 2024 05:11:09 +0100 Subject: [PATCH] Fix binary formatting for integers 2 and 3 (#1123) --- libc/fmt/formatbinary64.c | 2 +- test/libc/fmt/formatbinary64_test.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libc/fmt/formatbinary64.c b/libc/fmt/formatbinary64.c index 588eaad5d..70b316856 100644 --- a/libc/fmt/formatbinary64.c +++ b/libc/fmt/formatbinary64.c @@ -21,7 +21,7 @@ static inline int PickGoodWidth(unsigned x) { if (x < 16) { - if (x < 2) return 0; + if (x < 2) return 1; if (x < 8) return 7; return 15; } else { diff --git a/test/libc/fmt/formatbinary64_test.c b/test/libc/fmt/formatbinary64_test.c index b4801d0c9..fda0df92e 100644 --- a/test/libc/fmt/formatbinary64_test.c +++ b/test/libc/fmt/formatbinary64_test.c @@ -40,13 +40,13 @@ TEST(FormatBinary64, test2) { } TEST(FormatBinary64, test3) { - EXPECT_EQ(3, FormatBinary64(buf, 1, 2) - buf); - EXPECT_STREQ("0b1", buf); + EXPECT_EQ(4, FormatBinary64(buf, 1, 2) - buf); + EXPECT_STREQ("0b01", buf); } TEST(FormatBinary64, test4) { - EXPECT_EQ(1, FormatBinary64(buf, 1, 0) - buf); - EXPECT_STREQ("1", buf); + EXPECT_EQ(2, FormatBinary64(buf, 1, 0) - buf); + EXPECT_STREQ("01", buf); } TEST(FormatBinary64, test5) {