Skip to content

Commit

Permalink
Correction for printing long type variables in 32-bit system (#2094)
Browse files Browse the repository at this point in the history
Due to change request from #2037
  • Loading branch information
shajder authored Oct 1, 2024
1 parent cd74e02 commit 0395a1e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
1 change: 0 additions & 1 deletion test_conformance/printf/test_printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ struct printDataGenParameters

// Reference results - filled out at run-time
static std::vector<std::string> correctBufferInt;
static std::vector<std::string> correctBufferLong;
static std::vector<std::string> correctBufferHalf;
static std::vector<std::string> correctBufferFloat;
static std::vector<std::string> correctBufferDouble;
Expand Down
37 changes: 28 additions & 9 deletions test_conformance/printf/util_printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -158,6 +157,33 @@ std::vector<printDataGenParameters> 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<std::string> correctBufferLong = {

"10000000000",

"-10000000000 ",

"000010000000000",

" -10000000000",

"+10000000000 ",

"000010000000000",

"-000010000000000"

};

//-----------------------------------------------

// test case for long |
Expand All @@ -172,7 +198,7 @@ testCase testCaseLong = {

printLongGenParameters,

longRefBuilder,
NULL,

klong

Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 0395a1e

Please sign in to comment.