aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--format.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/format.c b/format.c
index d2b75b9b..a32db538 100644
--- a/format.c
+++ b/format.c
@@ -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);
-
- do {
- tmp = xreallocarray(tmp, 2, tmplen);
- tmplen *= 2;
- } while (strftime(tmp, tmplen, fmt, tm) == 0);
-
- expanded = format_expand(ft, tmp);
- free(tmp);
+ if (strftime(s, sizeof s, fmt, tm) == 0)
+ return (xstrdup(""));
- return (expanded);
+ return (format_expand(ft, s));
}
/* Expand keys in a template. */