aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/bar.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2016-12-15 17:39:09 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2016-12-15 19:01:40 -0500
commit248df18c24d2a849de984b477ca3913ce7c72441 (patch)
tree35beb85ecfcc54574d3b5e82c8445eb8c1219689 /sway/commands/bar.c
parentHandle border-related malloc failures (diff)
downloadsway-248df18c24d2a849de984b477ca3913ce7c72441.tar.gz
sway-248df18c24d2a849de984b477ca3913ce7c72441.tar.zst
sway-248df18c24d2a849de984b477ca3913ce7c72441.zip
Handle allocation failure in commands
Diffstat (limited to 'sway/commands/bar.c')
-rw-r--r--sway/commands/bar.c9
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) {
32 32
33 // Create new bar with default values 33 // Create new bar with default values
34 struct bar_config *bar = default_bar_config(); 34 struct bar_config *bar = default_bar_config();
35 if (!bar) {
36 return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar state");
37 }
35 38
36 // set bar id 39 // set bar id
37 int i; 40 int i;
@@ -39,7 +42,11 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
39 if (bar == config->bars->items[i]) { 42 if (bar == config->bars->items[i]) {
40 const int len = 5 + numlen(i); // "bar-" + i + \0 43 const int len = 5 + numlen(i); // "bar-" + i + \0
41 bar->id = malloc(len * sizeof(char)); 44 bar->id = malloc(len * sizeof(char));
42 snprintf(bar->id, len, "bar-%d", i); 45 if (bar->id) {
46 snprintf(bar->id, len, "bar-%d", i);
47 } else {
48 return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar ID");
49 }
43 break; 50 break;
44 } 51 }
45 } 52 }