aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c14
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) {
386 if (!results) { 386 if (!results) {
387 int len = strlen(criteria) + strlen(head) + 4; 387 int len = strlen(criteria) + strlen(head) + 4;
388 char *tmp = malloc(len); 388 char *tmp = malloc(len);
389 snprintf(tmp, len, "[%s] %s", criteria, head); 389 if (tmp) {
390 snprintf(tmp, len, "[%s] %s", criteria, head);
391 } else {
392 sway_log(L_DEBUG, "Unable to allocate criteria string for cmd result");
393 }
390 results = cmd_results_new(CMD_INVALID, tmp, 394 results = cmd_results_new(CMD_INVALID, tmp,
391 "Can't handle criteria string: Refusing to execute command"); 395 "Can't handle criteria string: Refusing to execute command");
392 free(tmp); 396 free(tmp);
@@ -584,6 +588,10 @@ cleanup:
584 588
585struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *format, ...) { 589struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *format, ...) {
586 struct cmd_results *results = malloc(sizeof(struct cmd_results)); 590 struct cmd_results *results = malloc(sizeof(struct cmd_results));
591 if (!results) {
592 sway_log(L_ERROR, "Unable to allocate command results");
593 return NULL;
594 }
587 results->status = status; 595 results->status = status;
588 if (input) { 596 if (input) {
589 results->input = strdup(input); // input is the command name 597 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
594 char *error = malloc(256); 602 char *error = malloc(256);
595 va_list args; 603 va_list args;
596 va_start(args, format); 604 va_start(args, format);
597 vsnprintf(error, 256, format, args); 605 if (error) {
606 vsnprintf(error, 256, format, args);
607 }
598 va_end(args); 608 va_end(args);
599 results->error = error; 609 results->error = error;
600 } else { 610 } else {