Use a fixed buffer for strftime() because there is no portable way to

tell if the buffer is too small, and an expanding buffer is overkill
anyway.
pull/432/head
nicm 2016-05-23 20:39:26 +00:00
parent e81a92449e
commit 95a4cc3bce
1 changed files with 4 additions and 13 deletions

View File

@ -850,27 +850,18 @@ fail:
char *
format_expand_time(struct format_tree *ft, const char *fmt, time_t t)
{
char *tmp, *expanded;
size_t tmplen;
struct tm *tm;
char s[2048];
if (fmt == NULL || *fmt == '\0')
return (xstrdup(""));
tm = localtime(&t);
tmp = NULL;
tmplen = strlen(fmt);
if (strftime(s, sizeof s, fmt, tm) == 0)
return (xstrdup(""));
do {
tmp = xreallocarray(tmp, 2, tmplen);
tmplen *= 2;
} while (strftime(tmp, tmplen, fmt, tm) == 0);
expanded = format_expand(ft, tmp);
free(tmp);
return (expanded);
return (format_expand(ft, s));
}
/* Expand keys in a template. */