summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-03-30 18:06:15 -0400
committerRich Felker <dalias@aerifal.cx>2011-03-30 18:06:15 -0400
commit6cdb371a202c15e624a79483b717e1302d84ac9f (patch)
tree57896f2db25d1687f8f9737efa578d12ae6c4506
parent22ec3cfd85228b6910f2f6b61626eb13c14636d7 (diff)
downloadlibc-testsuite-6cdb371a202c15e624a79483b717e1302d84ac9f.tar.gz
test printing tiny doubles - use ascii arithmetic to check result
-rw-r--r--snprintf.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/snprintf.c b/snprintf.c
index 8d06add..ea28e18 100644
--- a/snprintf.c
+++ b/snprintf.c
@@ -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");