summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2018-05-29 09:10:31 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2018-05-29 09:10:31 +0000
commit0ec093de19065b96090ec27641924a426774b957 (patch)
treebb9a343d18350eade5af6300d4c0cbffedd2ecf2 /usr.bin/tmux
parentb904a189a43174c76410825e9ba03618b4e1915f (diff)
If foo doesn't exist and can't be expanded in #{?foo,a,b} then assume it
is false.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/format.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index 2d8a2bf69c6..c29edf6f8cf 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.155 2018/05/22 08:49:12 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.156 2018/05/29 09:10:30 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1042,8 +1042,18 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
*ptr = '\0';
found = format_find(ft, copy + 1, modifiers);
- if (found == NULL)
+ if (found == NULL) {
+ /*
+ * If the conditional not found, try to expand it. If
+ * the expansion doesn't have any effect, then assume
+ * false.
+ */
found = format_expand(ft, copy + 1);
+ if (strcmp(found, copy + 1) == 0) {
+ free(found);
+ found = xstrdup("");
+ }
+ }
if (format_choose(ptr + 1, &left, &right) != 0)
goto fail;
@@ -1098,8 +1108,8 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
value = new;
}
- /* Expand the buffer and copy in the value. */
done:
+ /* Expand the buffer and copy in the value. */
valuelen = strlen(value);
while (*len - *off < valuelen + 1) {
*buf = xreallocarray(*buf, 2, *len);