#18098 closed bug (fixed)
snprintf: different results on 32 and 64 bits.
Reported by: | bipolar | Owned by: | korli |
---|---|---|---|
Priority: | normal | Milestone: | R1/beta4 |
Component: | System/libroot.so | Version: | R1/beta4 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description (last modified by )
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'").
Edit: Just in case... original wget2 test function: https://gitlab.com/gnuwget/wget2/-/blob/master/unit-tests/test.c#L326 that has the failing cases on 32 bits.
Change History (6)
comment:1 by , 2 years ago
Description: | modified (diff) |
---|
comment:2 by , 2 years ago
Component: | - General → System/libroot.so |
---|---|
Milestone: | Unscheduled → R1/beta4 |
Owner: | changed from | to
Status: | new → assigned |
comment:4 by , 2 years ago
Milestone: | R1/beta4 → R1/beta5 |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
comment:6 by , 2 years ago
Milestone: | R1/beta5 → R1/beta4 |
---|
https://review.haiku-os.org/c/haiku/+/5833