From 5fb5984e941cade797acac8f80b471c2dba58de8 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 16 May 2019 22:56:58 +0000 Subject: bar: fix segfault with missing or invalid bar id 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. --- sway/commands/bar/workspace_buttons.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'sway/commands/bar/workspace_buttons.c') diff --git a/sway/commands/bar/workspace_buttons.c b/sway/commands/bar/workspace_buttons.c index 792ef605..6bfb1616 100644 --- a/sway/commands/bar/workspace_buttons.c +++ b/sway/commands/bar/workspace_buttons.c @@ -9,10 +9,7 @@ struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) { if ((error = checkarg(argc, "workspace_buttons", EXPECTED_EQUAL_TO, 1))) { return error; } - if (!config->current_bar) { - return cmd_results_new(CMD_FAILURE, "No bar defined."); - } - config->current_bar->workspace_buttons = + config->current_bar->workspace_buttons = parse_boolean(argv[0], config->current_bar->workspace_buttons); if (config->current_bar->workspace_buttons) { sway_log(SWAY_DEBUG, "Enabling workspace buttons on bar: %s", -- cgit v1.2.3