aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/bar/bind.c
diff options
context:
space:
mode:
authorLibravatar Alyssa Ross <hi@alyssa.is>2019-05-16 22:56:58 +0000
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-05-21 10:16:26 -0400
commite12b3667a94ce78adb974cb4f94d0ffbe58c4290 (patch)
treedbf350b55669a112f7dd27ad3bcaee94b7b0dae1 /sway/commands/bar/bind.c
parentinput/keyboard: attempt default keymap on failure (diff)
downloadsway-e12b3667a94ce78adb974cb4f94d0ffbe58c4290.tar.gz
sway-e12b3667a94ce78adb974cb4f94d0ffbe58c4290.tar.zst
sway-e12b3667a94ce78adb974cb4f94d0ffbe58c4290.zip
bar: fix segfault with missing or invalid bar id1.1-rc3
Prior to this patch, if I ran something like this, sway would crash: swaymsg bar height 50 or swaymsg bar not-a-bar-id color bg #ff0000 This was in contrast to other bar subcommands, like status_command, which would exit with a "No bar defined" message. The difference between the subcommands that crashed and the ones that exited was that some subcommands had a check to see if a bar was specified, while others just assumed that it had been and carried on until they segfaulted. Because this check was identical in every subcommand it was present in, and I couldn't think of a case where it would be valid to run a bar subcommand without specifying which bar to apply it to, I moved this check from individual subcommands into the bar command, which is already responsible for actually setting the specified bar. This reduced code duplication, and fixed the crash for the subcommands that were missing this check.
Diffstat (limited to 'sway/commands/bar/bind.c')
-rw-r--r--sway/commands/bar/bind.c3
1 files changed, 0 insertions, 3 deletions
diff --git a/sway/commands/bar/bind.c b/sway/commands/bar/bind.c
index f94b4811..b4b5bc45 100644
--- a/sway/commands/bar/bind.c
+++ b/sway/commands/bar/bind.c
@@ -75,9 +75,6 @@ static struct cmd_results *bar_cmd_bind(int argc, char **argv, bool code,
75 if ((error = checkarg(argc, command, EXPECTED_AT_LEAST, minargs))) { 75 if ((error = checkarg(argc, command, EXPECTED_AT_LEAST, minargs))) {
76 return error; 76 return error;
77 } 77 }
78 if (!config->current_bar) {
79 return cmd_results_new(CMD_FAILURE, "No bar defined.");
80 }
81 78
82 struct bar_binding *binding = calloc(1, sizeof(struct bar_binding)); 79 struct bar_binding *binding = calloc(1, sizeof(struct bar_binding));
83 if (!binding) { 80 if (!binding) {