summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2016-05-23 20:39:26 +0000
committernicm <nicm@openbsd.org>2016-05-23 20:39:26 +0000
commit1cee2c3f20506704401d93812a430a9ce38c33dd (patch)
treeabafa2139a2eb649fea4e6d8c7cd9196dbec3e82
parentPlace a cpu-dependent trap/illegal instruction over the remainder of the (diff)
downloadwireguard-openbsd-1cee2c3f20506704401d93812a430a9ce38c33dd.tar.xz
wireguard-openbsd-1cee2c3f20506704401d93812a430a9ce38c33dd.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--usr.bin/tmux/format.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index 241b3cb3be0..16d495748df 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.106 2016/04/29 14:05:24 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.107 2016/05/23 20:39:26 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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. */