diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-03-30 18:06:15 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-03-30 18:06:15 -0400 |
commit | 6cdb371a202c15e624a79483b717e1302d84ac9f (patch) | |
tree | 57896f2db25d1687f8f9737efa578d12ae6c4506 /snprintf.c | |
parent | 22ec3cfd85228b6910f2f6b61626eb13c14636d7 (diff) | |
download | libc-testsuite-6cdb371a202c15e624a79483b717e1302d84ac9f.tar.gz |
test printing tiny doubles - use ascii arithmetic to check result
Diffstat (limited to 'snprintf.c')
-rw-r--r-- | snprintf.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -91,9 +91,9 @@ static const struct { int test_snprintf(void) { - int i, j; + int i, j, k; int err=0; - char b[500], *s; + char b[2000], *s; TEST(i, snprintf(0, 0, "%d", 123456), 6, "length returned %d != %d"); TEST(i, snprintf(0, 0, "%.4s", "hello"), 4, "length returned %d != %d"); @@ -104,6 +104,20 @@ int test_snprintf(void) TEST_S(b, "123", "incorrect output"); TEST(i, b[5], 'x', "buffer overrun"); + /* Perform ascii arithmetic to test printing tiny doubles */ + TEST(i, snprintf(b, sizeof b, "%.1022f", 0x1p-1021), 1024, "%d != %d"); + b[1] = '0'; + for (i=0; i<1021; i++) { + for (k=0, j=1023; j>0; j--) { + if (b[j]<'5') b[j]+=b[j]-'0'+k, k=0; + else b[j]+=b[j]-'0'-10+k, k=1; + } + } + TEST(i, b[1], '1', "'%c' != '%c'"); + for (j=2; b[j]=='0'; j++); + TEST(i, j, 1024, "%d != %d"); + + #ifndef DISABLE_SLOW_TESTS errno = 0; TEST(i, snprintf(NULL, 0, "%.*u", 2147483647, 0), 2147483647, "cannot print max length %d"); |