From 3d0a377e265f90d3417e8aef97e7b5205cd3fd71 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Mon, 20 Feb 2017 17:58:08 -0800 Subject: [PATCH] correct printf handling of %x with long ints Fixes #3352 --- src/builtin_printf.cpp | 2 ++ tests/printf.err | 1 + tests/printf.in | 9 +++++++++ tests/printf.out | 6 ++++++ 4 files changed, 18 insertions(+) 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