mirror of
https://github.com/tmux/tmux.git
synced 2025-09-01 20:57:00 +00:00
Make options_tostring allocate its result instead of using a stack
buffer (needed for something in the future).
This commit is contained in:
27
format.c
27
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. */
|
||||
|
Reference in New Issue
Block a user