From 0395a1efef72a100d7055be9bd3d7fb9ce3a45e1 Mon Sep 17 00:00:00 2001 From: Marcin Hajder Date: Tue, 1 Oct 2024 17:45:39 +0200 Subject: [PATCH] Correction for printing long type variables in 32-bit system (#2094) Due to change request from #2037 --- test_conformance/printf/test_printf.h | 1 - test_conformance/printf/util_printf.cpp | 37 +++++++++++++++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/test_conformance/printf/test_printf.h b/test_conformance/printf/test_printf.h index 7e5156a2..ad1e08fb 100644 --- a/test_conformance/printf/test_printf.h +++ b/test_conformance/printf/test_printf.h @@ -81,7 +81,6 @@ struct printDataGenParameters // Reference results - filled out at run-time static std::vector correctBufferInt; -static std::vector correctBufferLong; static std::vector correctBufferHalf; static std::vector correctBufferFloat; static std::vector correctBufferDouble; diff --git a/test_conformance/printf/util_printf.cpp b/test_conformance/printf/util_printf.cpp index 82183edb..4584b8cc 100644 --- a/test_conformance/printf/util_printf.cpp +++ b/test_conformance/printf/util_printf.cpp @@ -23,7 +23,6 @@ // Helpers for generating runtime reference results static void intRefBuilder(printDataGenParameters&, char*, const size_t); -static void longRefBuilder(printDataGenParameters&, char*, const size_t); static void halfRefBuilder(printDataGenParameters&, char* rResult, const size_t); static void floatRefBuilder(printDataGenParameters&, char* rResult, const size_t); @@ -158,6 +157,33 @@ std::vector printLongGenParameters = { }; +//-------------------------------------------------------- + +// Lookup table - [string]long-correct buffer | + +//-------------------------------------------------------- + +// The table below is used to accommodate differences in `printf` output when +// using the `%ld` format specifier in 32-bit versus 64-bit compiled binaries + +std::vector correctBufferLong = { + + "10000000000", + + "-10000000000 ", + + "000010000000000", + + " -10000000000", + + "+10000000000 ", + + "000010000000000", + + "-000010000000000" + +}; + //----------------------------------------------- // test case for long | @@ -172,7 +198,7 @@ testCase testCaseLong = { printLongGenParameters, - longRefBuilder, + NULL, klong @@ -1594,13 +1620,6 @@ static void intRefBuilder(printDataGenParameters& params, char* refResult, const atoi(params.dataRepresentation)); } -static void longRefBuilder(printDataGenParameters& params, char* refResult, - const size_t refSize) -{ - snprintf(refResult, refSize, params.genericFormats.front().c_str(), - atoll(params.dataRepresentation)); -} - static void halfRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize) {