diff options
author | kraftwerk28 <kefirchik3@gmail.com> | 2022-06-15 18:50:57 +0300 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-06-16 09:32:44 +0200 |
commit | 49cef51e6e7fe31ba4f820560e0b69ebd2149d37 (patch) | |
tree | 361a2995cd48c2b879705a30024c76cebb857522 /sway | |
parent | 1c69d0e72fe868d0fa2f6d7d9f9b4b3d7a3f78b4 (diff) |
Allocate enough space for `cmd_results->error`
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/sway/commands.c b/sway/commands.c index 0ced71ec..2160a970 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -485,13 +485,19 @@ struct cmd_results *cmd_results_new(enum cmd_status status, } results->status = status; if (format) { - char *error = malloc(256); + char *error = NULL; va_list args; va_start(args, format); - if (error) { - vsnprintf(error, 256, format, args); - } + int slen = vsnprintf(NULL, 0, format, args); va_end(args); + if (slen > 0) { + error = malloc(slen + 1); + if (error != NULL) { + va_start(args, format); + vsnprintf(error, slen + 1, format, args); + va_end(args); + } + } results->error = error; } else { results->error = NULL; |