Opened 2 years ago

Last modified 2 years ago

#18098 closed bug

snprintf: different results on 32 and 64 bits. — at Initial Version

Reported by: bipolar Owned by: nobody
Priority: normal Milestone: R1/beta4
Component: System/libroot.so Version: R1/beta4
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

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: ''
(%0lli, 0) - Expected: '0' got: ''
(%0llu, 0) - Expected: '0' got: ''
(%00lld, 0) - Expected: '0' got: ''
(%00lli, 0) - Expected: '0' got: ''
(%00llu, 0) - Expected: '0' got: ''

Output on 64 bits:

> test_snprintf
(%0lld, 0) - Expected: '0' got: '0'
(%0lli, 0) - Expected: '0' got: '0'
(%0llu, 0) - Expected: '0' got: '0'
(%00lld, 0) - Expected: '0' got: '0'
(%00lli, 0) - Expected: '0' got: '0'
(%00llu, 0) - Expected: '0' got: '0'

Not sure about how important this difference in behavior might be (or if I'm also messing things up in that test), but...

At least this is easy to reproduce.

(just to be clear, the wget2 test-suite expects the behavior seen on the 64 bits version, thus my use of "Expected: '0'").

Change History (0)

Note: See TracTickets for help on using tickets.