aboutsummaryrefslogtreecommitdiff
path: root/format.c
diff options
context:
space:
mode:
authornicm <nicm>2019-04-25 18:18:55 +0000
committernicm <nicm>2019-04-25 18:18:55 +0000
commit32a81e197bce3b16113c7603a766773c1a5cdcaf (patch)
tree64a3819ff876c804c171a01e6444fda3dc7ff465 /format.c
parent1677bb0deaa0e5c3e962e36ce98076b0db8507f6 (diff)
downloadrtmux-32a81e197bce3b16113c7603a766773c1a5cdcaf.tar.gz
rtmux-32a81e197bce3b16113c7603a766773c1a5cdcaf.tar.bz2
rtmux-32a81e197bce3b16113c7603a766773c1a5cdcaf.zip
Make options_tostring allocate its result instead of using a stack
buffer (needed for something in the future).
Diffstat (limited to 'format.c')
-rw-r--r--format.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/format.c b/format.c
index e544e6b3..abcdb1d7 100644
--- a/format.c
+++ b/format.c
@@ -904,9 +904,8 @@ format_find(struct format_tree *ft, const char *key, int modifiers)
struct environ_entry *envent;
static char s[64];
struct options_entry *o;
- const char *found;
int idx;
- char *copy, *saved;
+ char *found, *saved;
if (~modifiers & FORMAT_TIMESTRING) {
o = options_parse_get(global_options, key, &idx, 0);
@@ -933,12 +932,11 @@ format_find(struct format_tree *ft, const char *key, int modifiers)
return (NULL);
ctime_r(&fe->t, s);
s[strcspn(s, "\n")] = '\0';
- found = s;
+ found = xstrdup(s);
goto found;
}
if (fe->t != 0) {
- xsnprintf(s, sizeof s, "%lld", (long long)fe->t);
- found = s;
+ xasprintf(&found, "%lld", (long long)fe->t);
goto found;
}
if (fe->value == NULL && fe->cb != NULL) {
@@ -946,7 +944,7 @@ format_find(struct format_tree *ft, const char *key, int modifiers)
if (fe->value == NULL)
fe->value = xstrdup("");
}
- found = fe->value;
+ found = xstrdup(fe->value);
goto found;
}
@@ -957,7 +955,7 @@ format_find(struct format_tree *ft, const char *key, int modifiers)
if (envent == NULL)
envent = environ_find(global_environ, key);
if (envent != NULL) {
- found = envent->value;
+ found = xstrdup(envent->value);
goto found;
}
}
@@ -967,23 +965,22 @@ format_find(struct format_tree *ft, const char *key, int modifiers)
found:
if (found == NULL)
return (NULL);
- copy = xstrdup(found);
if (modifiers & FORMAT_BASENAME) {
- saved = copy;
- copy = xstrdup(basename(saved));
+ saved = found;
+ found = xstrdup(basename(saved));
free(saved);
}
if (modifiers & FORMAT_DIRNAME) {
- saved = copy;
- copy = xstrdup(dirname(saved));
+ saved = found;
+ found = xstrdup(dirname(saved));
free(saved);
}
if (modifiers & FORMAT_QUOTE) {
- saved = copy;
- copy = xstrdup(format_quote(saved));
+ saved = found;
+ found = xstrdup(format_quote(saved));
free(saved);
}
- return (copy);
+ return (found);
}
/* Skip until end. */