Fix missing null termination when tz_sec = 0, add test for it

This commit is contained in:
Laurence Withers 2008-01-07 13:16:18 +00:00
parent 048196532e
commit 6246f8ebcd
2 changed files with 6 additions and 1 deletions

View File

@ -155,6 +155,7 @@ char* iso8601_print(char* str, int amt, const struct iso8601_date* date,
else snprintf(str, amt, "%02d", y);
} else {
*str++ = 'Z';
*str++ = 0;
}
return str_orig;

View File

@ -204,7 +204,7 @@ int main(int argc, char* argv[])
int ret = 0;
struct iso8601_date dt;
struct iso8601_details details, details2;
char buf[100], buf2[100];
char buf[40], buf2[40];
const struct test* test;
if(argc == 2 && !strcmp(argv[1], "--print-summary")) {
@ -215,7 +215,11 @@ int main(int argc, char* argv[])
iso8601_now(&dt, &details);
printf("%-30s %-30s %s\n", "Name", "Basic format", "Extended format");
for(test = tests; test->desc; ++test) {
memset(buf, 'X', sizeof(buf));
memset(buf2, 'X', sizeof(buf2)); /* test null-termination */
test->do_details(&details2, &details);
iso8601_print(buf, sizeof(buf), &dt, &details2);
++details2.extended;
iso8601_print(buf2, sizeof(buf2), &dt, &details2);