diff options
author | Drew DeVault <[email protected]> | 2016-12-15 17:39:09 -0500 |
---|---|---|
committer | Drew DeVault <[email protected]> | 2016-12-15 19:01:40 -0500 |
commit | 248df18c24d2a849de984b477ca3913ce7c72441 (patch) | |
tree | 35beb85ecfcc54574d3b5e82c8445eb8c1219689 /sway/commands/bar.c | |
parent | 8691ff1b63655c6fb11fd2ffe90770e7de707963 (diff) |
Handle allocation failure in commands
Diffstat (limited to 'sway/commands/bar.c')
-rw-r--r-- | sway/commands/bar.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/sway/commands/bar.c b/sway/commands/bar.c index 55cb0d9d..e8d24084 100644 --- a/sway/commands/bar.c +++ b/sway/commands/bar.c @@ -32,6 +32,9 @@ struct cmd_results *cmd_bar(int argc, char **argv) { // Create new bar with default values struct bar_config *bar = default_bar_config(); + if (!bar) { + return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar state"); + } // set bar id int i; @@ -39,7 +42,11 @@ struct cmd_results *cmd_bar(int argc, char **argv) { if (bar == config->bars->items[i]) { const int len = 5 + numlen(i); // "bar-" + i + \0 bar->id = malloc(len * sizeof(char)); - snprintf(bar->id, len, "bar-%d", i); + if (bar->id) { + snprintf(bar->id, len, "bar-%d", i); + } else { + return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar ID"); + } break; } } |