From 6c06b70911d2c3c4bb60aac65ad8fc504a12746a Mon Sep 17 00:00:00 2001 From: Peter Ross Date: Tue, 1 Mar 2022 19:50:19 +1100 Subject: [PATCH] LibC: Set PRI[xX]8/PRI[xX]16 macros to `x` and `X` Described in: The macros were first added in a7a456002e91d9f13793e23aab4c24519c4e87c7, but it is not clear why the PRIx16/32 macros were defined as 'b' & 'w'. PrintfImplementation was never able to parse these values. --- Tests/LibC/TestSnprintf.cpp | 10 ++++++++++ Userland/Libraries/LibC/inttypes.h | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Tests/LibC/TestSnprintf.cpp b/Tests/LibC/TestSnprintf.cpp index 7346200922..bfb03d18d7 100644 --- a/Tests/LibC/TestSnprintf.cpp +++ b/Tests/LibC/TestSnprintf.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #pragma GCC diagnostic ignored "-Wformat-nonliteral" @@ -263,3 +265,11 @@ TEST_CASE(hexadecimal_values) EXPECT(test_single({ LITERAL("xxx\0"), "|%x|", 0, 3, LITERAL("|0|\0") })); EXPECT(test_single({ LITERAL("xxx\0"), "|%#x|", 0, 3, LITERAL("|0|\0") })); } + +TEST_CASE(inttypes_macros) +{ + EXPECT(test_single({ LITERAL("xxxxx"), "|%" PRIx8 "|", 0xAB, 4, LITERAL("|ab|\0") })); + EXPECT(test_single({ LITERAL("xxxxx"), "|%" PRIX8 "|", 0xAB, 4, LITERAL("|AB|\0") })); + EXPECT(test_single({ LITERAL("xxxxxxx"), "|%" PRIx16 "|", 0xC0DE, 6, LITERAL("|c0de|\0") })); + EXPECT(test_single({ LITERAL("xxxxxxx"), "|%" PRIX16 "|", 0xC0DE, 6, LITERAL("|C0DE|\0") })); +} diff --git a/Userland/Libraries/LibC/inttypes.h b/Userland/Libraries/LibC/inttypes.h index 6c479dd123..695928876d 100644 --- a/Userland/Libraries/LibC/inttypes.h +++ b/Userland/Libraries/LibC/inttypes.h @@ -41,10 +41,10 @@ __BEGIN_DECLS # define PRIu64 "lu" # define PRIuPTR "lx" #endif -#define PRIx8 "b" -#define PRIX8 "hhX" -#define PRIx16 "w" -#define PRIX16 "hX" +#define PRIx8 "x" +#define PRIX8 "X" +#define PRIx16 "x" +#define PRIX16 "X" #define PRIx32 "x" #define PRIX32 "X" #ifndef __x86_64__