diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-12-15 17:39:09 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2016-12-15 19:01:40 -0500 |
commit | 248df18c24d2a849de984b477ca3913ce7c72441 (patch) | |
tree | 35beb85ecfcc54574d3b5e82c8445eb8c1219689 /sway/commands/bar | |
parent | Handle border-related malloc failures (diff) | |
download | sway-248df18c24d2a849de984b477ca3913ce7c72441.tar.gz sway-248df18c24d2a849de984b477ca3913ce7c72441.tar.zst sway-248df18c24d2a849de984b477ca3913ce7c72441.zip |
Handle allocation failure in commands
Diffstat (limited to 'sway/commands/bar')
-rw-r--r-- | sway/commands/bar/bindsym.c | 3 | ||||
-rw-r--r-- | sway/commands/bar/colors.c | 6 |
2 files changed, 9 insertions, 0 deletions
diff --git a/sway/commands/bar/bindsym.c b/sway/commands/bar/bindsym.c index bb81b4a9..5f90b51a 100644 --- a/sway/commands/bar/bindsym.c +++ b/sway/commands/bar/bindsym.c | |||
@@ -26,6 +26,9 @@ struct cmd_results *bar_cmd_bindsym(int argc, char **argv) { | |||
26 | return cmd_results_new(CMD_INVALID, "bindsym", "Invalid mouse binding %s", argv[1]); | 26 | return cmd_results_new(CMD_INVALID, "bindsym", "Invalid mouse binding %s", argv[1]); |
27 | } | 27 | } |
28 | struct sway_mouse_binding *binding = malloc(sizeof(struct sway_mouse_binding)); | 28 | struct sway_mouse_binding *binding = malloc(sizeof(struct sway_mouse_binding)); |
29 | if (!binding) { | ||
30 | return cmd_results_new(CMD_FAILURE, "bindsym", "Unable to allocate binding"); | ||
31 | } | ||
29 | binding->button = numbutton; | 32 | binding->button = numbutton; |
30 | binding->command = join_args(argv + 1, argc - 1); | 33 | binding->command = join_args(argv + 1, argc - 1); |
31 | 34 | ||
diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c index f6fb520a..f8792973 100644 --- a/sway/commands/bar/colors.c +++ b/sway/commands/bar/colors.c | |||
@@ -9,6 +9,9 @@ static struct cmd_results *parse_single_color(char **color, const char *cmd_name | |||
9 | 9 | ||
10 | if (!*color) { | 10 | if (!*color) { |
11 | *color = malloc(10); | 11 | *color = malloc(10); |
12 | if (!*color) { | ||
13 | return cmd_results_new(CMD_FAILURE, cmd_name, "Unable to allocate color"); | ||
14 | } | ||
12 | } | 15 | } |
13 | 16 | ||
14 | error = add_color(cmd_name, *color, argv[0]); | 17 | error = add_color(cmd_name, *color, argv[0]); |
@@ -29,6 +32,9 @@ static struct cmd_results *parse_three_colors(char ***colors, const char *cmd_na | |||
29 | for (i = 0; i < 3; i++) { | 32 | for (i = 0; i < 3; i++) { |
30 | if (!*colors[i]) { | 33 | if (!*colors[i]) { |
31 | *(colors[i]) = malloc(10); | 34 | *(colors[i]) = malloc(10); |
35 | if (!*(colors[i])) { | ||
36 | return cmd_results_new(CMD_FAILURE, cmd_name, "Unable to allocate color"); | ||
37 | } | ||
32 | } | 38 | } |
33 | error = add_color(cmd_name, *(colors[i]), argv[i]); | 39 | error = add_color(cmd_name, *(colors[i]), argv[i]); |
34 | if (error) { | 40 | if (error) { |