aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2018-05-29 11:02:26 +0100
committerThomas Adam <thomas@xteddy.org>2018-05-29 11:02:26 +0100
commit54cd292f09147797e10ae90512e3cb357ce3caca (patch)
treef9842d966659d5a6daaf99d343edbccd8db5135a
parent058d2b94dc6cad58b8c500988eb91580b6afe397 (diff)
parentd1f5142daba11baf77f7ec1753b5a660585e96f9 (diff)
downloadrtmux-54cd292f09147797e10ae90512e3cb357ce3caca.tar.gz
rtmux-54cd292f09147797e10ae90512e3cb357ce3caca.tar.bz2
rtmux-54cd292f09147797e10ae90512e3cb357ce3caca.zip
Merge branch 'obsd-master'
-rw-r--r--format.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/format.c b/format.c
index 5e7cff50..705968c5 100644
--- a/format.c
+++ b/format.c
@@ -1058,8 +1058,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;
@@ -1114,8 +1124,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);