aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/bar/font.c
diff options
context:
space:
mode:
authorLibravatar Alyssa Ross <hi@alyssa.is>2019-05-16 22:56:58 +0000
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-05-17 15:33:57 -0400
commit5fb5984e941cade797acac8f80b471c2dba58de8 (patch)
tree37abf5915420bcf84e44ec41007e6bf66615ca6c /sway/commands/bar/font.c
parentAdd infos to help using for_window to man 5 (diff)
downloadsway-5fb5984e941cade797acac8f80b471c2dba58de8.tar.gz
sway-5fb5984e941cade797acac8f80b471c2dba58de8.tar.zst
sway-5fb5984e941cade797acac8f80b471c2dba58de8.zip
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.
Diffstat (limited to 'sway/commands/bar/font.c')
-rw-r--r--sway/commands/bar/font.c3
1 files changed, 0 insertions, 3 deletions
diff --git a/sway/commands/bar/font.c b/sway/commands/bar/font.c
index cf1f759e..62987f3e 100644
--- a/sway/commands/bar/font.c
+++ b/sway/commands/bar/font.c
@@ -9,9 +9,6 @@ struct cmd_results *bar_cmd_font(int argc, char **argv) {
9 if ((error = checkarg(argc, "font", EXPECTED_AT_LEAST, 1))) { 9 if ((error = checkarg(argc, "font", EXPECTED_AT_LEAST, 1))) {
10 return error; 10 return error;
11 } 11 }
12 if (!config->current_bar) {
13 return cmd_results_new(CMD_FAILURE, "No bar defined.");
14 }
15 char *font = join_args(argv, argc); 12 char *font = join_args(argv, argc);
16 free(config->current_bar->font); 13 free(config->current_bar->font);
17 config->current_bar->font = font; 14 config->current_bar->font = font;