diff --git a/src/builtin_printf.cpp b/src/builtin_printf.cpp index 4f41505e2..3ec49dd8b 100644 --- a/src/builtin_printf.cpp +++ b/src/builtin_printf.cpp @@ -437,6 +437,8 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc // Create a copy of the % directive, with an intmax_t-wide width modifier substituted for any // existing integer length modifier. switch (conversion) { + case L'x': + case L'X': case L'd': case L'i': case L'u': { diff --git a/tests/printf.err b/tests/printf.err index 8ba50d3ff..e04bd0f0f 100644 --- a/tests/printf.err +++ b/tests/printf.err @@ -1 +1,2 @@ 2,34: value not completely converted +0xABCDEF12345678901: Result too large diff --git a/tests/printf.in b/tests/printf.in index 073bfc582..366b34921 100644 --- a/tests/printf.in +++ b/tests/printf.in @@ -61,3 +61,12 @@ else echo '3,450000e+00' echo '4,560000e+00' end + +# Verify long long ints are handled correctly. See issue #3352. +printf 'long hex1 %x\n' 498216206234 +printf 'long hex2 %X\n' 498216206234 +printf 'long hex3 %X\n' 0xABCDEF1234567890 +printf 'long hex4 %X\n' 0xABCDEF12345678901 +printf 'long decimal %d\n' 498216206594 +printf 'long signed %d\n' -498216206595 +printf 'long signed to unsigned %u\n' -498216206596 diff --git a/tests/printf.out b/tests/printf.out index ab25c97d5..b965be413 100644 --- a/tests/printf.out +++ b/tests/printf.out @@ -18,3 +18,9 @@ a 1.230000e+00 3,450000e+00 4,560000e+00 +long hex1 73ffffff9a +long hex2 73FFFFFF9A +long hex3 ABCDEF1234567890 +long hex4 long decimal 498216206594 +long signed -498216206595 +long signed to unsigned 18446743575493345020