#18098: snprintf: different results on 32 and 64 bits.
-----------------------+--------------------------
Reporter: bipolar | Owner: nobody
Type: bug | Status: new
Priority: normal | Milestone: Unscheduled
Component: - General | Version: R1/beta4
Keywords: | Blocked By:
Blocking: | Platform: All
-----------------------+--------------------------
While running the wget2 test-suite, Begasus found some failing tests (see
https://github.com/haikuports/haikuports/pull/7484).
I've managed to distill/recreate the failing test cases with the following
`test_snprintf` small program:
{{{
#include <stdio.h>
int main(void)
{
char* fmts[]={"%0lld","%0lli","%0llu","%00lld","%00lli",
"%00llu"};
char result[32];
int i;
for (i=0; i < 6; i++) {
// Without using "(long long int)0" here, the 32 bits
versions output a different
// big number (like "141014943242649600") on each run,
instead of "".
// On 64 bits, using just 0, works ok (output is "0").
snprintf(result, sizeof(result), fmts[i], (long long
int)0);
printf("(%s, 0) - Expected: '0' got: '%s'\n", fmts[i],
result);
}
return 0;
}
}}}
Output on 32 bits (on both gcc2 and gcc11):
{{{
test_snprintf(%0lld, 0) - Expected: '0' got: ''
test_snprintf(%0lld, 0) - Expected: '0' got: '0'