From 10c8b73075fa0dd5512cc14be7240ec47f68dece Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 15 Dec 2016 18:26:53 -0500 Subject: Handle calloc failures --- sway/commands/assign.c | 5 ++++- sway/commands/output.c | 3 +++ sway/commands/workspace.c | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'sway/commands') diff --git a/sway/commands/assign.c b/sway/commands/assign.c index 1824692b..992b4692 100644 --- a/sway/commands/assign.c +++ b/sway/commands/assign.c @@ -23,11 +23,14 @@ struct cmd_results *cmd_assign(int argc, char **argv) { char *movecmd = "move container to workspace "; int arglen = strlen(movecmd) + strlen(*argv) + 1; char *cmdlist = calloc(1, arglen); - + if (!cmdlist) { + return cmd_results_new(CMD_FAILURE, "assign", "Unable to allocate command list"); + } snprintf(cmdlist, arglen, "%s%s", movecmd, *argv); struct criteria *crit = malloc(sizeof(struct criteria)); if (!crit) { + free(cmdlist); return cmd_results_new(CMD_FAILURE, "assign", "Unable to allocate criteria"); } crit->crit_raw = strdup(criteria); diff --git a/sway/commands/output.c b/sway/commands/output.c index e150aed2..01ac9f4e 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c @@ -26,6 +26,9 @@ struct cmd_results *cmd_output(int argc, char **argv) { const char *name = argv[0]; struct output_config *output = calloc(1, sizeof(struct output_config)); + if (!output) { + return cmd_results_new(CMD_FAILURE, "output", "Unable to allocate output config"); + } output->x = output->y = output->width = output->height = -1; output->name = strdup(name); output->enabled = -1; diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index 35224f8a..14fe242f 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c @@ -61,6 +61,10 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { return error; } struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); + if (!wso) { + return cmd_results_new(CMD_FAILURE, "workspace output", + "Unable to allocate workspace output"); + } wso->workspace = strdup(argv[0]); wso->output = strdup(argv[2]); int i = -1; -- cgit v1.2.3