aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornicm <nicm>2016-05-23 20:39:26 +0000
committernicm <nicm>2016-05-23 20:39:26 +0000
commit95a4cc3bcef95feb6dfca7557cef4c32a424e4d4 (patch)
tree6a6176d29a8e81e7b899be94c986909fa43fb532
parente81a92449ea45b58cc6ff8ae1d7d46bf6b312694 (diff)
downloadrtmux-95a4cc3bcef95feb6dfca7557cef4c32a424e4d4.tar.gz
rtmux-95a4cc3bcef95feb6dfca7557cef4c32a424e4d4.tar.bz2
rtmux-95a4cc3bcef95feb6dfca7557cef4c32a424e4d4.zip
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.
-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. */