diff options
author | Ulrich Drepper <drepper@redhat.com> | 2003-01-19 10:05:55 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2003-01-19 10:05:55 +0000 |
commit | b1a173f75e8292448bc186c502f1dd2df10ef72c (patch) | |
tree | 24701745d7b7e7e86af8fafd5d3ed9b9973c187e /time/tst-strftime.c | |
parent | 6675b19146f30d626c5adf4c59e0626a2dc2afd0 (diff) | |
download | glibc-b1a173f75e8292448bc186c502f1dd2df10ef72c.zip glibc-b1a173f75e8292448bc186c502f1dd2df10ef72c.tar.gz glibc-b1a173f75e8292448bc186c502f1dd2df10ef72c.tar.bz2 |
Update.
2003-01-19 Ulrich Drepper <drepper@redhat.com>
* time/strftime.c (my_strftime): Handle very large width
specifications for numeric values correctly. Improve checks for
overflow.
* time/Makefile (tests): Add tst-strftime.
* time/tst-strftime.c: New file.
Diffstat (limited to 'time/tst-strftime.c')
-rw-r--r-- | time/tst-strftime.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/time/tst-strftime.c b/time/tst-strftime.c new file mode 100644 index 0000000..1feb741 --- /dev/null +++ b/time/tst-strftime.c @@ -0,0 +1,74 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + + +static struct +{ + const char *fmt; + size_t min; + size_t max; +} tests[] = + { + { "%2000Y", 2000, 4000 }, + { "%02000Y", 2000, 4000 }, + { "%_2000Y", 2000, 4000 }, + { "%-2000Y", 2000, 4000 }, + }; +#define ntests (sizeof (tests) / sizeof (tests[0])) + + +static int +do_test (void) +{ + size_t cnt; + int result = 0; + + time_t tnow = time (NULL); + struct tm *now = localtime (&tnow); + + for (cnt = 0; cnt < ntests; ++cnt) + { + size_t size = 0; + int res; + char *buf = NULL; + + do + { + size += 500; + buf = (char *) realloc (buf, size); + if (buf == NULL) + { + puts ("out of memory"); + exit (1); + } + + res = strftime (buf, size, tests[cnt].fmt, now); + if (res != 0) + break; + } + while (size < tests[cnt].max); + + if (res == 0) + { + printf ("%Zu: %s: res == 0 despite size == %Zu\n", + cnt, tests[cnt].fmt, size); + result = 1; + } + else if (size < tests[cnt].min) + { + printf ("%Zu: %s: size == %Zu was enough\n", + cnt, tests[cnt].fmt, size); + result = 1; + } + else + printf ("%Zu: %s: size == %Zu: OK\n", cnt, tests[cnt].fmt, size); + + free (buf); + } + + return result; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" |