diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/sway/commands.c b/sway/commands.c index d87d0084..dee03d71 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -386,7 +386,11 @@ struct cmd_results *handle_command(char *_exec, enum command_context context) { if (!results) { int len = strlen(criteria) + strlen(head) + 4; char *tmp = malloc(len); - snprintf(tmp, len, "[%s] %s", criteria, head); + if (tmp) { + snprintf(tmp, len, "[%s] %s", criteria, head); + } else { + sway_log(L_DEBUG, "Unable to allocate criteria string for cmd result"); + } results = cmd_results_new(CMD_INVALID, tmp, "Can't handle criteria string: Refusing to execute command"); free(tmp); @@ -584,6 +588,10 @@ cleanup: struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *format, ...) { struct cmd_results *results = malloc(sizeof(struct cmd_results)); + if (!results) { + sway_log(L_ERROR, "Unable to allocate command results"); + return NULL; + } results->status = status; if (input) { results->input = strdup(input); // input is the command name @@ -594,7 +602,9 @@ struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, c char *error = malloc(256); va_list args; va_start(args, format); - vsnprintf(error, 256, format, args); + if (error) { + vsnprintf(error, 256, format, args); + } va_end(args); results->error = error; } else { |