diff options
author | emersion <contact@emersion.fr> | 2018-07-02 09:06:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-02 09:06:02 +0100 |
commit | defb73596fedec846280b9155bb3e9d210da49bb (patch) | |
tree | 0a3e6c9e5efaf0e8bb5f01ab7691350cd063ebcb | |
parent | Merge pull request #2190 from emersion/screencopy (diff) | |
parent | swaylock daemonize: fix leak of devnull fd (diff) | |
download | sway-defb73596fedec846280b9155bb3e9d210da49bb.tar.gz sway-defb73596fedec846280b9155bb3e9d210da49bb.tar.zst sway-defb73596fedec846280b9155bb3e9d210da49bb.zip |
Merge pull request #2186 from martinetd/static-analysis
Static analysis fixes
30 files changed, 113 insertions, 62 deletions
diff --git a/common/unicode.c b/common/unicode.c index 38a9b48e..5070e083 100644 --- a/common/unicode.c +++ b/common/unicode.c | |||
@@ -92,7 +92,7 @@ static const struct { | |||
92 | 92 | ||
93 | int utf8_size(const char *s) { | 93 | int utf8_size(const char *s) { |
94 | uint8_t c = (uint8_t)*s; | 94 | uint8_t c = (uint8_t)*s; |
95 | for (size_t i = 0; i < sizeof(sizes) / 2; ++i) { | 95 | for (size_t i = 0; i < sizeof(sizes) / sizeof(*sizes); ++i) { |
96 | if ((c & sizes[i].mask) == sizes[i].result) { | 96 | if ((c & sizes[i].mask) == sizes[i].result) { |
97 | return sizes[i].octets; | 97 | return sizes[i].octets; |
98 | } | 98 | } |
diff --git a/common/util.c b/common/util.c index fb7f9454..678926ed 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -95,7 +95,7 @@ pid_t get_parent_pid(pid_t child) { | |||
95 | token = strtok(NULL, sep); // parent pid | 95 | token = strtok(NULL, sep); // parent pid |
96 | parent = strtol(token, NULL, 10); | 96 | parent = strtol(token, NULL, 10); |
97 | } | 97 | } |
98 | 98 | free(buffer); | |
99 | fclose(stat); | 99 | fclose(stat); |
100 | } | 100 | } |
101 | 101 | ||
diff --git a/sway/commands.c b/sway/commands.c index 5b20857a..5b67e1ec 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -428,8 +428,7 @@ struct cmd_results *config_commands_command(char *exec) { | |||
428 | 428 | ||
429 | struct cmd_handler *handler = find_handler(cmd, NULL, 0); | 429 | struct cmd_handler *handler = find_handler(cmd, NULL, 0); |
430 | if (!handler && strcmp(cmd, "*") != 0) { | 430 | if (!handler && strcmp(cmd, "*") != 0) { |
431 | char *input = cmd ? cmd : "(empty)"; | 431 | results = cmd_results_new(CMD_INVALID, cmd, "Unknown/invalid command"); |
432 | results = cmd_results_new(CMD_INVALID, input, "Unknown/invalid command"); | ||
433 | goto cleanup; | 432 | goto cleanup; |
434 | } | 433 | } |
435 | 434 | ||
@@ -471,10 +470,12 @@ struct cmd_results *config_commands_command(char *exec) { | |||
471 | } | 470 | } |
472 | if (!policy) { | 471 | if (!policy) { |
473 | policy = alloc_command_policy(cmd); | 472 | policy = alloc_command_policy(cmd); |
474 | sway_assert(policy, "Unable to allocate security policy"); | 473 | if (!sway_assert(policy, "Unable to allocate security policy")) { |
475 | if (policy) { | 474 | results = cmd_results_new(CMD_INVALID, cmd, |
476 | list_add(config->command_policies, policy); | 475 | "Unable to allocate memory"); |
476 | goto cleanup; | ||
477 | } | 477 | } |
478 | list_add(config->command_policies, policy); | ||
478 | } | 479 | } |
479 | policy->context = context; | 480 | policy->context = context; |
480 | 481 | ||
diff --git a/sway/commands/assign.c b/sway/commands/assign.c index 9d15e166..a90498ce 100644 --- a/sway/commands/assign.c +++ b/sway/commands/assign.c | |||
@@ -27,6 +27,7 @@ struct cmd_results *cmd_assign(int argc, char **argv) { | |||
27 | 27 | ||
28 | if (strncmp(*argv, "→", strlen("→")) == 0) { | 28 | if (strncmp(*argv, "→", strlen("→")) == 0) { |
29 | if (argc < 3) { | 29 | if (argc < 3) { |
30 | free(criteria); | ||
30 | return cmd_results_new(CMD_INVALID, "assign", "Missing workspace"); | 31 | return cmd_results_new(CMD_INVALID, "assign", "Missing workspace"); |
31 | } | 32 | } |
32 | ++argv; | 33 | ++argv; |
diff --git a/sway/commands/bar/font.c b/sway/commands/bar/font.c index 80b7a593..f036cbc3 100644 --- a/sway/commands/bar/font.c +++ b/sway/commands/bar/font.c | |||
@@ -14,7 +14,7 @@ struct cmd_results *bar_cmd_font(int argc, char **argv) { | |||
14 | } | 14 | } |
15 | char *font = join_args(argv, argc); | 15 | char *font = join_args(argv, argc); |
16 | free(config->current_bar->font); | 16 | free(config->current_bar->font); |
17 | config->current_bar->font = strdup(font); | 17 | config->current_bar->font = font; |
18 | wlr_log(L_DEBUG, "Settings font '%s' for bar: %s", | 18 | wlr_log(L_DEBUG, "Settings font '%s' for bar: %s", |
19 | config->current_bar->font, config->current_bar->id); | 19 | config->current_bar->font, config->current_bar->id); |
20 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 20 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
diff --git a/sway/commands/bar/modifier.c b/sway/commands/bar/modifier.c index 7ba4b125..02f845e6 100644 --- a/sway/commands/bar/modifier.c +++ b/sway/commands/bar/modifier.c | |||
@@ -22,9 +22,10 @@ struct cmd_results *bar_cmd_modifier(int argc, char **argv) { | |||
22 | mod |= tmp_mod; | 22 | mod |= tmp_mod; |
23 | continue; | 23 | continue; |
24 | } else { | 24 | } else { |
25 | error = cmd_results_new(CMD_INVALID, "modifier", | ||
26 | "Unknown modifier '%s'", split->items[i]); | ||
25 | free_flat_list(split); | 27 | free_flat_list(split); |
26 | return cmd_results_new(CMD_INVALID, "modifier", | 28 | return error; |
27 | "Unknown modifier '%s'", split->items[i]); | ||
28 | } | 29 | } |
29 | } | 30 | } |
30 | free_flat_list(split); | 31 | free_flat_list(split); |
diff --git a/sway/commands/input/accel_profile.c b/sway/commands/input/accel_profile.c index 37d6e133..a4108ec3 100644 --- a/sway/commands/input/accel_profile.c +++ b/sway/commands/input/accel_profile.c | |||
@@ -23,6 +23,7 @@ struct cmd_results *input_cmd_accel_profile(int argc, char **argv) { | |||
23 | } else if (strcasecmp(argv[0], "flat") == 0) { | 23 | } else if (strcasecmp(argv[0], "flat") == 0) { |
24 | new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; | 24 | new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; |
25 | } else { | 25 | } else { |
26 | free_input_config(new_config); | ||
26 | return cmd_results_new(CMD_INVALID, "accel_profile", | 27 | return cmd_results_new(CMD_INVALID, "accel_profile", |
27 | "Expected 'accel_profile <adaptive|flat>'"); | 28 | "Expected 'accel_profile <adaptive|flat>'"); |
28 | } | 29 | } |
diff --git a/sway/commands/input/click_method.c b/sway/commands/input/click_method.c index 8f1f0aa7..5d0d8cc2 100644 --- a/sway/commands/input/click_method.c +++ b/sway/commands/input/click_method.c | |||
@@ -26,6 +26,7 @@ struct cmd_results *input_cmd_click_method(int argc, char **argv) { | |||
26 | } else if (strcasecmp(argv[0], "clickfinger") == 0) { | 26 | } else if (strcasecmp(argv[0], "clickfinger") == 0) { |
27 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; | 27 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; |
28 | } else { | 28 | } else { |
29 | free_input_config(new_config); | ||
29 | return cmd_results_new(CMD_INVALID, "click_method", | 30 | return cmd_results_new(CMD_INVALID, "click_method", |
30 | "Expected 'click_method <none|button_areas|clickfinger'"); | 31 | "Expected 'click_method <none|button_areas|clickfinger'"); |
31 | } | 32 | } |
diff --git a/sway/commands/input/drag_lock.c b/sway/commands/input/drag_lock.c index 8273a7d4..9e32816f 100644 --- a/sway/commands/input/drag_lock.c +++ b/sway/commands/input/drag_lock.c | |||
@@ -23,6 +23,7 @@ struct cmd_results *input_cmd_drag_lock(int argc, char **argv) { | |||
23 | } else if (strcasecmp(argv[0], "disabled") == 0) { | 23 | } else if (strcasecmp(argv[0], "disabled") == 0) { |
24 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; | 24 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; |
25 | } else { | 25 | } else { |
26 | free_input_config(new_config); | ||
26 | return cmd_results_new(CMD_INVALID, "drag_lock", | 27 | return cmd_results_new(CMD_INVALID, "drag_lock", |
27 | "Expected 'drag_lock <enabled|disabled>'"); | 28 | "Expected 'drag_lock <enabled|disabled>'"); |
28 | } | 29 | } |
diff --git a/sway/commands/input/dwt.c b/sway/commands/input/dwt.c index 995a2f47..73937507 100644 --- a/sway/commands/input/dwt.c +++ b/sway/commands/input/dwt.c | |||
@@ -22,6 +22,7 @@ struct cmd_results *input_cmd_dwt(int argc, char **argv) { | |||
22 | } else if (strcasecmp(argv[0], "disabled") == 0) { | 22 | } else if (strcasecmp(argv[0], "disabled") == 0) { |
23 | new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED; | 23 | new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED; |
24 | } else { | 24 | } else { |
25 | free_input_config(new_config); | ||
25 | return cmd_results_new(CMD_INVALID, "dwt", | 26 | return cmd_results_new(CMD_INVALID, "dwt", |
26 | "Expected 'dwt <enabled|disabled>'"); | 27 | "Expected 'dwt <enabled|disabled>'"); |
27 | } | 28 | } |
diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c index 2217f5ce..e2ccdc94 100644 --- a/sway/commands/input/events.c +++ b/sway/commands/input/events.c | |||
@@ -29,6 +29,7 @@ struct cmd_results *input_cmd_events(int argc, char **argv) { | |||
29 | new_config->send_events = | 29 | new_config->send_events = |
30 | LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; | 30 | LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; |
31 | } else { | 31 | } else { |
32 | free_input_config(new_config); | ||
32 | return cmd_results_new(CMD_INVALID, "events", | 33 | return cmd_results_new(CMD_INVALID, "events", |
33 | "Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); | 34 | "Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); |
34 | } | 35 | } |
diff --git a/sway/commands/input/left_handed.c b/sway/commands/input/left_handed.c index 94b8e03e..769ce98c 100644 --- a/sway/commands/input/left_handed.c +++ b/sway/commands/input/left_handed.c | |||
@@ -23,6 +23,7 @@ struct cmd_results *input_cmd_left_handed(int argc, char **argv) { | |||
23 | } else if (strcasecmp(argv[0], "disabled") == 0) { | 23 | } else if (strcasecmp(argv[0], "disabled") == 0) { |
24 | new_config->left_handed = 0; | 24 | new_config->left_handed = 0; |
25 | } else { | 25 | } else { |
26 | free_input_config(new_config); | ||
26 | return cmd_results_new(CMD_INVALID, "left_handed", | 27 | return cmd_results_new(CMD_INVALID, "left_handed", |
27 | "Expected 'left_handed <enabled|disabled>'"); | 28 | "Expected 'left_handed <enabled|disabled>'"); |
28 | } | 29 | } |
diff --git a/sway/commands/input/map_from_region.c b/sway/commands/input/map_from_region.c index 80bb856d..40f04214 100644 --- a/sway/commands/input/map_from_region.c +++ b/sway/commands/input/map_from_region.c | |||
@@ -54,20 +54,28 @@ struct cmd_results *input_cmd_map_from_region(int argc, char **argv) { | |||
54 | bool mm1, mm2; | 54 | bool mm1, mm2; |
55 | if (!parse_coords(argv[0], &new_config->mapped_from_region->x1, | 55 | if (!parse_coords(argv[0], &new_config->mapped_from_region->x1, |
56 | &new_config->mapped_from_region->y1, &mm1)) { | 56 | &new_config->mapped_from_region->y1, &mm1)) { |
57 | free(new_config->mapped_from_region); | ||
58 | free_input_config(new_config); | ||
57 | return cmd_results_new(CMD_FAILURE, "map_from_region", | 59 | return cmd_results_new(CMD_FAILURE, "map_from_region", |
58 | "Invalid top-left coordinates"); | 60 | "Invalid top-left coordinates"); |
59 | } | 61 | } |
60 | if (!parse_coords(argv[1], &new_config->mapped_from_region->x2, | 62 | if (!parse_coords(argv[1], &new_config->mapped_from_region->x2, |
61 | &new_config->mapped_from_region->y2, &mm2)) { | 63 | &new_config->mapped_from_region->y2, &mm2)) { |
64 | free(new_config->mapped_from_region); | ||
65 | free_input_config(new_config); | ||
62 | return cmd_results_new(CMD_FAILURE, "map_from_region", | 66 | return cmd_results_new(CMD_FAILURE, "map_from_region", |
63 | "Invalid bottom-right coordinates"); | 67 | "Invalid bottom-right coordinates"); |
64 | } | 68 | } |
65 | if (new_config->mapped_from_region->x1 > new_config->mapped_from_region->x2 || | 69 | if (new_config->mapped_from_region->x1 > new_config->mapped_from_region->x2 || |
66 | new_config->mapped_from_region->y1 > new_config->mapped_from_region->y2) { | 70 | new_config->mapped_from_region->y1 > new_config->mapped_from_region->y2) { |
71 | free(new_config->mapped_from_region); | ||
72 | free_input_config(new_config); | ||
67 | return cmd_results_new(CMD_FAILURE, "map_from_region", | 73 | return cmd_results_new(CMD_FAILURE, "map_from_region", |
68 | "Invalid rectangle"); | 74 | "Invalid rectangle"); |
69 | } | 75 | } |
70 | if (mm1 != mm2) { | 76 | if (mm1 != mm2) { |
77 | free(new_config->mapped_from_region); | ||
78 | free_input_config(new_config); | ||
71 | return cmd_results_new(CMD_FAILURE, "map_from_region", | 79 | return cmd_results_new(CMD_FAILURE, "map_from_region", |
72 | "Both coordinates must be in the same unit"); | 80 | "Both coordinates must be in the same unit"); |
73 | } | 81 | } |
diff --git a/sway/commands/input/middle_emulation.c b/sway/commands/input/middle_emulation.c index a551fd51..7ca01629 100644 --- a/sway/commands/input/middle_emulation.c +++ b/sway/commands/input/middle_emulation.c | |||
@@ -24,6 +24,7 @@ struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) { | |||
24 | new_config->middle_emulation = | 24 | new_config->middle_emulation = |
25 | LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; | 25 | LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; |
26 | } else { | 26 | } else { |
27 | free_input_config(new_config); | ||
27 | return cmd_results_new(CMD_INVALID, "middle_emulation", | 28 | return cmd_results_new(CMD_INVALID, "middle_emulation", |
28 | "Expected 'middle_emulation <enabled|disabled>'"); | 29 | "Expected 'middle_emulation <enabled|disabled>'"); |
29 | } | 30 | } |
diff --git a/sway/commands/input/natural_scroll.c b/sway/commands/input/natural_scroll.c index c4e19b78..55236790 100644 --- a/sway/commands/input/natural_scroll.c +++ b/sway/commands/input/natural_scroll.c | |||
@@ -23,6 +23,7 @@ struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) { | |||
23 | } else if (strcasecmp(argv[0], "disabled") == 0) { | 23 | } else if (strcasecmp(argv[0], "disabled") == 0) { |
24 | new_config->natural_scroll = 0; | 24 | new_config->natural_scroll = 0; |
25 | } else { | 25 | } else { |
26 | free_input_config(new_config); | ||
26 | return cmd_results_new(CMD_INVALID, "natural_scroll", | 27 | return cmd_results_new(CMD_INVALID, "natural_scroll", |
27 | "Expected 'natural_scroll <enabled|disabled>'"); | 28 | "Expected 'natural_scroll <enabled|disabled>'"); |
28 | } | 29 | } |
diff --git a/sway/commands/input/pointer_accel.c b/sway/commands/input/pointer_accel.c index 171063aa..8bbd0724 100644 --- a/sway/commands/input/pointer_accel.c +++ b/sway/commands/input/pointer_accel.c | |||
@@ -20,6 +20,7 @@ struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) { | |||
20 | 20 | ||
21 | float pointer_accel = atof(argv[0]); | 21 | float pointer_accel = atof(argv[0]); |
22 | if (pointer_accel < -1 || pointer_accel > 1) { | 22 | if (pointer_accel < -1 || pointer_accel > 1) { |
23 | free_input_config(new_config); | ||
23 | return cmd_results_new(CMD_INVALID, "pointer_accel", | 24 | return cmd_results_new(CMD_INVALID, "pointer_accel", |
24 | "Input out of range [-1, 1]"); | 25 | "Input out of range [-1, 1]"); |
25 | } | 26 | } |
diff --git a/sway/commands/input/repeat_delay.c b/sway/commands/input/repeat_delay.c index ce265841..c9ddbf0e 100644 --- a/sway/commands/input/repeat_delay.c +++ b/sway/commands/input/repeat_delay.c | |||
@@ -20,6 +20,7 @@ struct cmd_results *input_cmd_repeat_delay(int argc, char **argv) { | |||
20 | 20 | ||
21 | int repeat_delay = atoi(argv[0]); | 21 | int repeat_delay = atoi(argv[0]); |
22 | if (repeat_delay < 0) { | 22 | if (repeat_delay < 0) { |
23 | free_input_config(new_config); | ||
23 | return cmd_results_new(CMD_INVALID, "repeat_delay", | 24 | return cmd_results_new(CMD_INVALID, "repeat_delay", |
24 | "Repeat delay cannot be negative"); | 25 | "Repeat delay cannot be negative"); |
25 | } | 26 | } |
diff --git a/sway/commands/input/repeat_rate.c b/sway/commands/input/repeat_rate.c index f2ea2e69..56878176 100644 --- a/sway/commands/input/repeat_rate.c +++ b/sway/commands/input/repeat_rate.c | |||
@@ -20,6 +20,7 @@ struct cmd_results *input_cmd_repeat_rate(int argc, char **argv) { | |||
20 | 20 | ||
21 | int repeat_rate = atoi(argv[0]); | 21 | int repeat_rate = atoi(argv[0]); |
22 | if (repeat_rate < 0) { | 22 | if (repeat_rate < 0) { |
23 | free_input_config(new_config); | ||
23 | return cmd_results_new(CMD_INVALID, "repeat_rate", | 24 | return cmd_results_new(CMD_INVALID, "repeat_rate", |
24 | "Repeat rate cannot be negative"); | 25 | "Repeat rate cannot be negative"); |
25 | } | 26 | } |
diff --git a/sway/commands/input/scroll_method.c b/sway/commands/input/scroll_method.c index 0a1c57ac..4c6ac6b6 100644 --- a/sway/commands/input/scroll_method.c +++ b/sway/commands/input/scroll_method.c | |||
@@ -27,6 +27,7 @@ struct cmd_results *input_cmd_scroll_method(int argc, char **argv) { | |||
27 | } else if (strcasecmp(argv[0], "on_button_down") == 0) { | 27 | } else if (strcasecmp(argv[0], "on_button_down") == 0) { |
28 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; | 28 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; |
29 | } else { | 29 | } else { |
30 | free_input_config(new_config); | ||
30 | return cmd_results_new(CMD_INVALID, "scroll_method", | 31 | return cmd_results_new(CMD_INVALID, "scroll_method", |
31 | "Expected 'scroll_method <none|two_finger|edge|on_button_down>'"); | 32 | "Expected 'scroll_method <none|two_finger|edge|on_button_down>'"); |
32 | } | 33 | } |
diff --git a/sway/commands/input/tap.c b/sway/commands/input/tap.c index e7f03058..7d027d5d 100644 --- a/sway/commands/input/tap.c +++ b/sway/commands/input/tap.c | |||
@@ -23,6 +23,7 @@ struct cmd_results *input_cmd_tap(int argc, char **argv) { | |||
23 | } else if (strcasecmp(argv[0], "disabled") == 0) { | 23 | } else if (strcasecmp(argv[0], "disabled") == 0) { |
24 | new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED; | 24 | new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED; |
25 | } else { | 25 | } else { |
26 | free_input_config(new_config); | ||
26 | return cmd_results_new(CMD_INVALID, "tap", | 27 | return cmd_results_new(CMD_INVALID, "tap", |
27 | "Expected 'tap <enabled|disabled>'"); | 28 | "Expected 'tap <enabled|disabled>'"); |
28 | } | 29 | } |
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 55cbdff0..65b5f902 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c | |||
@@ -81,8 +81,9 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { | |||
81 | // src file is inside configuration dir | 81 | // src file is inside configuration dir |
82 | 82 | ||
83 | char *conf = strdup(config->current_config); | 83 | char *conf = strdup(config->current_config); |
84 | if(!conf) { | 84 | if (!conf) { |
85 | wlr_log(L_ERROR, "Failed to duplicate string"); | 85 | wlr_log(L_ERROR, "Failed to duplicate string"); |
86 | free(src); | ||
86 | return cmd_results_new(CMD_FAILURE, "output", | 87 | return cmd_results_new(CMD_FAILURE, "output", |
87 | "Unable to allocate resources"); | 88 | "Unable to allocate resources"); |
88 | } | 89 | } |
diff --git a/sway/commands/output/mode.c b/sway/commands/output/mode.c index daec6d44..ef56ae9e 100644 --- a/sway/commands/output/mode.c +++ b/sway/commands/output/mode.c | |||
@@ -36,11 +36,11 @@ struct cmd_results *output_cmd_mode(int argc, char **argv) { | |||
36 | } | 36 | } |
37 | } else { | 37 | } else { |
38 | // Format is 1234 4321 | 38 | // Format is 1234 4321 |
39 | argc--; argv++; | ||
39 | if (!argc) { | 40 | if (!argc) { |
40 | return cmd_results_new(CMD_INVALID, "output", | 41 | return cmd_results_new(CMD_INVALID, "output", |
41 | "Missing mode argument (height)."); | 42 | "Missing mode argument (height)."); |
42 | } | 43 | } |
43 | argc--; argv++; | ||
44 | output->height = strtol(*argv, &end, 10); | 44 | output->height = strtol(*argv, &end, 10); |
45 | if (*end) { | 45 | if (*end) { |
46 | return cmd_results_new(CMD_INVALID, "output", | 46 | return cmd_results_new(CMD_INVALID, "output", |
diff --git a/sway/commands/output/position.c b/sway/commands/output/position.c index c2aeb281..449767b1 100644 --- a/sway/commands/output/position.c +++ b/sway/commands/output/position.c | |||
@@ -27,11 +27,11 @@ struct cmd_results *output_cmd_position(int argc, char **argv) { | |||
27 | } | 27 | } |
28 | } else { | 28 | } else { |
29 | // Format is 1234 4321 (legacy) | 29 | // Format is 1234 4321 (legacy) |
30 | argc--; argv++; | ||
30 | if (!argc) { | 31 | if (!argc) { |
31 | return cmd_results_new(CMD_INVALID, "output", | 32 | return cmd_results_new(CMD_INVALID, "output", |
32 | "Missing position argument (y)."); | 33 | "Missing position argument (y)."); |
33 | } | 34 | } |
34 | argc--; argv++; | ||
35 | config->handler_context.output_config->y = strtol(*argv, &end, 10); | 35 | config->handler_context.output_config->y = strtol(*argv, &end, 10); |
36 | if (*end) { | 36 | if (*end) { |
37 | return cmd_results_new(CMD_INVALID, "output", | 37 | return cmd_results_new(CMD_INVALID, "output", |
diff --git a/sway/config.c b/sway/config.c index 12a02163..0aae1696 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -302,6 +302,11 @@ static char *get_config_path(void) { | |||
302 | const char *current_config_path; | 302 | const char *current_config_path; |
303 | 303 | ||
304 | static bool load_config(const char *path, struct sway_config *config) { | 304 | static bool load_config(const char *path, struct sway_config *config) { |
305 | if (path == NULL) { | ||
306 | wlr_log(L_ERROR, "Unable to find a config file!"); | ||
307 | return false; | ||
308 | } | ||
309 | |||
305 | wlr_log(L_INFO, "Loading config from %s", path); | 310 | wlr_log(L_INFO, "Loading config from %s", path); |
306 | current_config_path = path; | 311 | current_config_path = path; |
307 | 312 | ||
@@ -310,11 +315,6 @@ static bool load_config(const char *path, struct sway_config *config) { | |||
310 | return false; | 315 | return false; |
311 | } | 316 | } |
312 | 317 | ||
313 | if (path == NULL) { | ||
314 | wlr_log(L_ERROR, "Unable to find a config file!"); | ||
315 | return false; | ||
316 | } | ||
317 | |||
318 | FILE *f = fopen(path, "r"); | 318 | FILE *f = fopen(path, "r"); |
319 | if (!f) { | 319 | if (!f) { |
320 | wlr_log(L_ERROR, "Unable to open %s for reading", path); | 320 | wlr_log(L_ERROR, "Unable to open %s for reading", path); |
@@ -425,7 +425,7 @@ static bool load_include_config(const char *path, const char *parent_dir, | |||
425 | // save parent config | 425 | // save parent config |
426 | const char *parent_config = config->current_config; | 426 | const char *parent_config = config->current_config; |
427 | 427 | ||
428 | char *full_path = strdup(path); | 428 | char *full_path; |
429 | int len = strlen(path); | 429 | int len = strlen(path); |
430 | if (len >= 1 && path[0] != '/') { | 430 | if (len >= 1 && path[0] != '/') { |
431 | len = len + strlen(parent_dir) + 2; | 431 | len = len + strlen(parent_dir) + 2; |
@@ -436,6 +436,8 @@ static bool load_include_config(const char *path, const char *parent_dir, | |||
436 | return false; | 436 | return false; |
437 | } | 437 | } |
438 | snprintf(full_path, len, "%s/%s", parent_dir, path); | 438 | snprintf(full_path, len, "%s/%s", parent_dir, path); |
439 | } else { | ||
440 | full_path = strdup(path); | ||
439 | } | 441 | } |
440 | 442 | ||
441 | char *real_path = realpath(full_path, NULL); | 443 | char *real_path = realpath(full_path, NULL); |
@@ -583,6 +585,8 @@ bool read_config(FILE *file, struct sway_config *config) { | |||
583 | } | 585 | } |
584 | char *expanded = expand_line(block, line, brace_detected > 0); | 586 | char *expanded = expand_line(block, line, brace_detected > 0); |
585 | if (!expanded) { | 587 | if (!expanded) { |
588 | list_foreach(stack, free); | ||
589 | list_free(stack); | ||
586 | return false; | 590 | return false; |
587 | } | 591 | } |
588 | wlr_log(L_DEBUG, "Expanded line: %s", expanded); | 592 | wlr_log(L_DEBUG, "Expanded line: %s", expanded); |
diff --git a/sway/config/bar.c b/sway/config/bar.c index 5a97c3cc..b97076a0 100644 --- a/sway/config/bar.c +++ b/sway/config/bar.c | |||
@@ -70,16 +70,12 @@ void free_bar_config(struct bar_config *bar) { | |||
70 | 70 | ||
71 | struct bar_config *default_bar_config(void) { | 71 | struct bar_config *default_bar_config(void) { |
72 | struct bar_config *bar = NULL; | 72 | struct bar_config *bar = NULL; |
73 | bar = malloc(sizeof(struct bar_config)); | 73 | bar = calloc(1, sizeof(struct bar_config)); |
74 | if (!bar) { | 74 | if (!bar) { |
75 | return NULL; | 75 | return NULL; |
76 | } | 76 | } |
77 | if (!(bar->mode = strdup("dock"))) goto cleanup; | ||
78 | if (!(bar->hidden_state = strdup("hide"))) goto cleanup; | ||
79 | bar->outputs = NULL; | 77 | bar->outputs = NULL; |
80 | bar->position = strdup("bottom"); | 78 | bar->position = strdup("bottom"); |
81 | if (!(bar->bindings = create_list())) goto cleanup; | ||
82 | if (!(bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p'; sleep 1; done"))) goto cleanup; | ||
83 | bar->pango_markup = false; | 79 | bar->pango_markup = false; |
84 | bar->swaybar_command = NULL; | 80 | bar->swaybar_command = NULL; |
85 | bar->font = NULL; | 81 | bar->font = NULL; |
@@ -91,6 +87,19 @@ struct bar_config *default_bar_config(void) { | |||
91 | bar->binding_mode_indicator = true; | 87 | bar->binding_mode_indicator = true; |
92 | bar->verbose = false; | 88 | bar->verbose = false; |
93 | bar->pid = 0; | 89 | bar->pid = 0; |
90 | if (!(bar->mode = strdup("dock"))) { | ||
91 | goto cleanup; | ||
92 | } | ||
93 | if (!(bar->hidden_state = strdup("hide"))) { | ||
94 | goto cleanup; | ||
95 | } | ||
96 | if (!(bar->bindings = create_list())) { | ||
97 | goto cleanup; | ||
98 | } | ||
99 | if (!(bar->status_command = | ||
100 | strdup("while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done"))) { | ||
101 | goto cleanup; | ||
102 | } | ||
94 | // set default colors | 103 | // set default colors |
95 | if (!(bar->colors.background = strndup("#000000ff", 9))) { | 104 | if (!(bar->colors.background = strndup("#000000ff", 9))) { |
96 | goto cleanup; | 105 | goto cleanup; |
@@ -174,7 +183,7 @@ void invoke_swaybar(struct bar_config *bar) { | |||
174 | if (!command) { | 183 | if (!command) { |
175 | const char msg[] = "Unable to allocate swaybar command string"; | 184 | const char msg[] = "Unable to allocate swaybar command string"; |
176 | size_t msg_len = sizeof(msg); | 185 | size_t msg_len = sizeof(msg); |
177 | if (write(filedes[1], &msg_len, sizeof(int))) {}; | 186 | if (write(filedes[1], &msg_len, sizeof(size_t))) {}; |
178 | if (write(filedes[1], msg, msg_len)) {}; | 187 | if (write(filedes[1], msg, msg_len)) {}; |
179 | close(filedes[1]); | 188 | close(filedes[1]); |
180 | exit(1); | 189 | exit(1); |
@@ -189,8 +198,8 @@ void invoke_swaybar(struct bar_config *bar) { | |||
189 | } | 198 | } |
190 | wlr_log(L_DEBUG, "Spawned swaybar %d", bar->pid); | 199 | wlr_log(L_DEBUG, "Spawned swaybar %d", bar->pid); |
191 | close(filedes[0]); | 200 | close(filedes[0]); |
192 | ssize_t len; | 201 | size_t len; |
193 | if (read(filedes[1], &len, sizeof(int)) == sizeof(int)) { | 202 | if (read(filedes[1], &len, sizeof(size_t)) == sizeof(size_t)) { |
194 | char *buf = malloc(len); | 203 | char *buf = malloc(len); |
195 | if(!buf) { | 204 | if(!buf) { |
196 | wlr_log(L_ERROR, "Cannot allocate error string"); | 205 | wlr_log(L_ERROR, "Cannot allocate error string"); |
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index d2932c87..cb524999 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c | |||
@@ -186,8 +186,8 @@ static void transaction_apply(struct sway_transaction *transaction) { | |||
186 | (now.tv_nsec - commit->tv_nsec) / 1000000.0; | 186 | (now.tv_nsec - commit->tv_nsec) / 1000000.0; |
187 | float ms_total = ms_arranging + ms_waiting; | 187 | float ms_total = ms_arranging + ms_waiting; |
188 | wlr_log(L_DEBUG, "Transaction %p: %.1fms arranging, %.1fms waiting, " | 188 | wlr_log(L_DEBUG, "Transaction %p: %.1fms arranging, %.1fms waiting, " |
189 | "%.1fms total (%.1f frames if 60Hz)", transaction, | 189 | "%.1fms total (%.1f frames if 60Hz)", transaction, |
190 | ms_arranging, ms_waiting, ms_total, ms_total / (1000 / 60)); | 190 | ms_arranging, ms_waiting, ms_total, ms_total / (1000.0f / 60)); |
191 | } | 191 | } |
192 | 192 | ||
193 | // Apply the instruction state to the container's current state | 193 | // Apply the instruction state to the container's current state |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 241fe742..3e510c2e 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -263,7 +263,10 @@ static void ipc_send_event(const char *json_string, enum ipc_command_type event) | |||
263 | client->current_command = event; | 263 | client->current_command = event; |
264 | if (!ipc_send_reply(client, json_string, (uint32_t) strlen(json_string))) { | 264 | if (!ipc_send_reply(client, json_string, (uint32_t) strlen(json_string))) { |
265 | wlr_log_errno(L_INFO, "Unable to send reply to IPC client"); | 265 | wlr_log_errno(L_INFO, "Unable to send reply to IPC client"); |
266 | ipc_client_disconnect(client); | 266 | /* ipc_send_reply destroys client on error, which also |
267 | * removes it from the list, so we need to process | ||
268 | * current index again */ | ||
269 | i--; | ||
267 | } | 270 | } |
268 | } | 271 | } |
269 | } | 272 | } |
@@ -383,9 +386,7 @@ void ipc_client_disconnect(struct ipc_client *client) { | |||
383 | return; | 386 | return; |
384 | } | 387 | } |
385 | 388 | ||
386 | if (client->fd != -1) { | 389 | shutdown(client->fd, SHUT_RDWR); |
387 | shutdown(client->fd, SHUT_RDWR); | ||
388 | } | ||
389 | 390 | ||
390 | wlr_log(L_INFO, "IPC Client %d disconnected", client->fd); | 391 | wlr_log(L_INFO, "IPC Client %d disconnected", client->fd); |
391 | wl_event_source_remove(client->event_source); | 392 | wl_event_source_remove(client->event_source); |
@@ -465,8 +466,7 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
465 | } | 466 | } |
466 | buf[client->payload_length] = '\0'; | 467 | buf[client->payload_length] = '\0'; |
467 | 468 | ||
468 | const char *error_denied = "{ \"success\": false, \"error\": \"Permission denied\" }"; | 469 | bool client_valid = true; |
469 | |||
470 | switch (client->current_command) { | 470 | switch (client->current_command) { |
471 | case IPC_COMMAND: | 471 | case IPC_COMMAND: |
472 | { | 472 | { |
@@ -474,7 +474,7 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
474 | const char *json = cmd_results_to_json(results); | 474 | const char *json = cmd_results_to_json(results); |
475 | char reply[256]; | 475 | char reply[256]; |
476 | int length = snprintf(reply, sizeof(reply), "%s", json); | 476 | int length = snprintf(reply, sizeof(reply), "%s", json); |
477 | ipc_send_reply(client, reply, (uint32_t) length); | 477 | client_valid = ipc_send_reply(client, reply, (uint32_t)length); |
478 | free_cmd_results(results); | 478 | free_cmd_results(results); |
479 | goto exit_cleanup; | 479 | goto exit_cleanup; |
480 | } | 480 | } |
@@ -497,7 +497,8 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
497 | } | 497 | } |
498 | } | 498 | } |
499 | const char *json_string = json_object_to_json_string(outputs); | 499 | const char *json_string = json_object_to_json_string(outputs); |
500 | ipc_send_reply(client, json_string, (uint32_t) strlen(json_string)); | 500 | client_valid = |
501 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | ||
501 | json_object_put(outputs); // free | 502 | json_object_put(outputs); // free |
502 | goto exit_cleanup; | 503 | goto exit_cleanup; |
503 | } | 504 | } |
@@ -508,7 +509,8 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
508 | container_for_each_descendant_dfs(&root_container, | 509 | container_for_each_descendant_dfs(&root_container, |
509 | ipc_get_workspaces_callback, workspaces); | 510 | ipc_get_workspaces_callback, workspaces); |
510 | const char *json_string = json_object_to_json_string(workspaces); | 511 | const char *json_string = json_object_to_json_string(workspaces); |
511 | ipc_send_reply(client, json_string, (uint32_t) strlen(json_string)); | 512 | client_valid = |
513 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | ||
512 | json_object_put(workspaces); // free | 514 | json_object_put(workspaces); // free |
513 | goto exit_cleanup; | 515 | goto exit_cleanup; |
514 | } | 516 | } |
@@ -518,7 +520,7 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
518 | // TODO: Check if they're permitted to use these events | 520 | // TODO: Check if they're permitted to use these events |
519 | struct json_object *request = json_tokener_parse(buf); | 521 | struct json_object *request = json_tokener_parse(buf); |
520 | if (request == NULL) { | 522 | if (request == NULL) { |
521 | ipc_send_reply(client, "{\"success\": false}", 18); | 523 | client_valid = ipc_send_reply(client, "{\"success\": false}", 18); |
522 | wlr_log_errno(L_INFO, "Failed to read request"); | 524 | wlr_log_errno(L_INFO, "Failed to read request"); |
523 | goto exit_cleanup; | 525 | goto exit_cleanup; |
524 | } | 526 | } |
@@ -539,7 +541,8 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
539 | } else if (strcmp(event_type, "binding") == 0) { | 541 | } else if (strcmp(event_type, "binding") == 0) { |
540 | client->subscribed_events |= event_mask(IPC_EVENT_BINDING); | 542 | client->subscribed_events |= event_mask(IPC_EVENT_BINDING); |
541 | } else { | 543 | } else { |
542 | ipc_send_reply(client, "{\"success\": false}", 18); | 544 | client_valid = |
545 | ipc_send_reply(client, "{\"success\": false}", 18); | ||
543 | json_object_put(request); | 546 | json_object_put(request); |
544 | wlr_log_errno(L_INFO, "Failed to parse request"); | 547 | wlr_log_errno(L_INFO, "Failed to parse request"); |
545 | goto exit_cleanup; | 548 | goto exit_cleanup; |
@@ -547,7 +550,7 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
547 | } | 550 | } |
548 | 551 | ||
549 | json_object_put(request); | 552 | json_object_put(request); |
550 | ipc_send_reply(client, "{\"success\": true}", 17); | 553 | client_valid = ipc_send_reply(client, "{\"success\": true}", 17); |
551 | goto exit_cleanup; | 554 | goto exit_cleanup; |
552 | } | 555 | } |
553 | 556 | ||
@@ -559,7 +562,8 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
559 | json_object_array_add(inputs, ipc_json_describe_input(device)); | 562 | json_object_array_add(inputs, ipc_json_describe_input(device)); |
560 | } | 563 | } |
561 | const char *json_string = json_object_to_json_string(inputs); | 564 | const char *json_string = json_object_to_json_string(inputs); |
562 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | 565 | client_valid = |
566 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | ||
563 | json_object_put(inputs); // free | 567 | json_object_put(inputs); // free |
564 | goto exit_cleanup; | 568 | goto exit_cleanup; |
565 | } | 569 | } |
@@ -572,7 +576,8 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
572 | json_object_array_add(seats, ipc_json_describe_seat(seat)); | 576 | json_object_array_add(seats, ipc_json_describe_seat(seat)); |
573 | } | 577 | } |
574 | const char *json_string = json_object_to_json_string(seats); | 578 | const char *json_string = json_object_to_json_string(seats); |
575 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | 579 | client_valid = |
580 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | ||
576 | json_object_put(seats); // free | 581 | json_object_put(seats); // free |
577 | goto exit_cleanup; | 582 | goto exit_cleanup; |
578 | } | 583 | } |
@@ -582,7 +587,8 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
582 | json_object *tree = | 587 | json_object *tree = |
583 | ipc_json_describe_container_recursive(&root_container); | 588 | ipc_json_describe_container_recursive(&root_container); |
584 | const char *json_string = json_object_to_json_string(tree); | 589 | const char *json_string = json_object_to_json_string(tree); |
585 | ipc_send_reply(client, json_string, (uint32_t) strlen(json_string)); | 590 | client_valid = |
591 | ipc_send_reply(client, json_string, (uint32_t) strlen(json_string)); | ||
586 | json_object_put(tree); | 592 | json_object_put(tree); |
587 | goto exit_cleanup; | 593 | goto exit_cleanup; |
588 | } | 594 | } |
@@ -593,7 +599,8 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
593 | container_descendants(&root_container, C_VIEW, ipc_get_marks_callback, | 599 | container_descendants(&root_container, C_VIEW, ipc_get_marks_callback, |
594 | marks); | 600 | marks); |
595 | const char *json_string = json_object_to_json_string(marks); | 601 | const char *json_string = json_object_to_json_string(marks); |
596 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | 602 | client_valid = |
603 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | ||
597 | json_object_put(marks); | 604 | json_object_put(marks); |
598 | goto exit_cleanup; | 605 | goto exit_cleanup; |
599 | } | 606 | } |
@@ -602,7 +609,8 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
602 | { | 609 | { |
603 | json_object *version = ipc_json_get_version(); | 610 | json_object *version = ipc_json_get_version(); |
604 | const char *json_string = json_object_to_json_string(version); | 611 | const char *json_string = json_object_to_json_string(version); |
605 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | 612 | client_valid = |
613 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | ||
606 | json_object_put(version); // free | 614 | json_object_put(version); // free |
607 | goto exit_cleanup; | 615 | goto exit_cleanup; |
608 | } | 616 | } |
@@ -617,7 +625,9 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
617 | json_object_array_add(bars, json_object_new_string(bar->id)); | 625 | json_object_array_add(bars, json_object_new_string(bar->id)); |
618 | } | 626 | } |
619 | const char *json_string = json_object_to_json_string(bars); | 627 | const char *json_string = json_object_to_json_string(bars); |
620 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | 628 | client_valid = |
629 | ipc_send_reply(client, json_string, | ||
630 | (uint32_t)strlen(json_string)); | ||
621 | json_object_put(bars); // free | 631 | json_object_put(bars); // free |
622 | } else { | 632 | } else { |
623 | // Send particular bar's details | 633 | // Send particular bar's details |
@@ -631,12 +641,15 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
631 | } | 641 | } |
632 | if (!bar) { | 642 | if (!bar) { |
633 | const char *error = "{ \"success\": false, \"error\": \"No bar with that ID\" }"; | 643 | const char *error = "{ \"success\": false, \"error\": \"No bar with that ID\" }"; |
634 | ipc_send_reply(client, error, (uint32_t)strlen(error)); | 644 | client_valid = |
645 | ipc_send_reply(client, error, (uint32_t)strlen(error)); | ||
635 | goto exit_cleanup; | 646 | goto exit_cleanup; |
636 | } | 647 | } |
637 | json_object *json = ipc_json_describe_bar_config(bar); | 648 | json_object *json = ipc_json_describe_bar_config(bar); |
638 | const char *json_string = json_object_to_json_string(json); | 649 | const char *json_string = json_object_to_json_string(json); |
639 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | 650 | client_valid = |
651 | ipc_send_reply(client, json_string, | ||
652 | (uint32_t)strlen(json_string)); | ||
640 | json_object_put(json); // free | 653 | json_object_put(json); // free |
641 | } | 654 | } |
642 | goto exit_cleanup; | 655 | goto exit_cleanup; |
@@ -647,11 +660,10 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
647 | goto exit_cleanup; | 660 | goto exit_cleanup; |
648 | } | 661 | } |
649 | 662 | ||
650 | ipc_send_reply(client, error_denied, (uint32_t)strlen(error_denied)); | ||
651 | wlr_log(L_DEBUG, "Denied IPC client access to %i", client->current_command); | ||
652 | |||
653 | exit_cleanup: | 663 | exit_cleanup: |
654 | client->payload_length = 0; | 664 | if (client_valid) { |
665 | client->payload_length = 0; | ||
666 | } | ||
655 | free(buf); | 667 | free(buf); |
656 | return; | 668 | return; |
657 | } | 669 | } |
diff --git a/sway/main.c b/sway/main.c index a325dc3a..124f9fbb 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -175,7 +175,7 @@ static void log_kernel() { | |||
175 | } | 175 | } |
176 | free(line); | 176 | free(line); |
177 | } | 177 | } |
178 | fclose(f); | 178 | pclose(f); |
179 | } | 179 | } |
180 | 180 | ||
181 | static void security_sanity_check() { | 181 | static void security_sanity_check() { |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 5eb4be0f..2db06a31 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -109,7 +109,6 @@ static bool workspace_valid_on_output(const char *output_name, | |||
109 | char *workspace_next_name(const char *output_name) { | 109 | char *workspace_next_name(const char *output_name) { |
110 | wlr_log(L_DEBUG, "Workspace: Generating new workspace name for output %s", | 110 | wlr_log(L_DEBUG, "Workspace: Generating new workspace name for output %s", |
111 | output_name); | 111 | output_name); |
112 | int l = 1; | ||
113 | // Scan all workspace bindings to find the next available workspace name, | 112 | // Scan all workspace bindings to find the next available workspace name, |
114 | // if none are found/available then default to a number | 113 | // if none are found/available then default to a number |
115 | struct sway_mode *mode = config->current_mode; | 114 | struct sway_mode *mode = config->current_mode; |
@@ -202,14 +201,9 @@ char *workspace_next_name(const char *output_name) { | |||
202 | // As a fall back, get the current number of active workspaces | 201 | // As a fall back, get the current number of active workspaces |
203 | // and return that + 1 for the next workspace's name | 202 | // and return that + 1 for the next workspace's name |
204 | int ws_num = root_container.children->length; | 203 | int ws_num = root_container.children->length; |
205 | if (ws_num >= 10) { | 204 | int l = snprintf(NULL, 0, "%d", ws_num); |
206 | l = 2; | ||
207 | } else if (ws_num >= 100) { | ||
208 | l = 3; | ||
209 | } | ||
210 | char *name = malloc(l + 1); | 205 | char *name = malloc(l + 1); |
211 | if (!name) { | 206 | if (!sway_assert(name, "Cloud not allocate workspace name")) { |
212 | wlr_log(L_ERROR, "Could not allocate workspace name"); | ||
213 | return NULL; | 207 | return NULL; |
214 | } | 208 | } |
215 | sprintf(name, "%d", ws_num++); | 209 | sprintf(name, "%d", ws_num++); |
@@ -271,6 +265,9 @@ struct sway_container *workspace_by_name(const char *name) { | |||
271 | */ | 265 | */ |
272 | struct sway_container *workspace_output_prev_next_impl( | 266 | struct sway_container *workspace_output_prev_next_impl( |
273 | struct sway_container *output, bool next) { | 267 | struct sway_container *output, bool next) { |
268 | if (!output) { | ||
269 | return NULL; | ||
270 | } | ||
274 | if (!sway_assert(output->type == C_OUTPUT, | 271 | if (!sway_assert(output->type == C_OUTPUT, |
275 | "Argument must be an output, is %d", output->type)) { | 272 | "Argument must be an output, is %d", output->type)) { |
276 | return NULL; | 273 | return NULL; |
@@ -303,6 +300,9 @@ struct sway_container *workspace_output_prev_next_impl( | |||
303 | */ | 300 | */ |
304 | struct sway_container *workspace_prev_next_impl( | 301 | struct sway_container *workspace_prev_next_impl( |
305 | struct sway_container *workspace, bool next) { | 302 | struct sway_container *workspace, bool next) { |
303 | if (!workspace) { | ||
304 | return NULL; | ||
305 | } | ||
306 | if (!sway_assert(workspace->type == C_WORKSPACE, | 306 | if (!sway_assert(workspace->type == C_WORKSPACE, |
307 | "Argument must be a workspace, is %d", workspace->type)) { | 307 | "Argument must be a workspace, is %d", workspace->type)) { |
308 | return NULL; | 308 | return NULL; |
diff --git a/swaylock/main.c b/swaylock/main.c index 591df7b4..f31ed679 100644 --- a/swaylock/main.c +++ b/swaylock/main.c | |||
@@ -42,6 +42,7 @@ static void daemonize() { | |||
42 | int devnull = open("/dev/null", O_RDWR); | 42 | int devnull = open("/dev/null", O_RDWR); |
43 | dup2(STDOUT_FILENO, devnull); | 43 | dup2(STDOUT_FILENO, devnull); |
44 | dup2(STDERR_FILENO, devnull); | 44 | dup2(STDERR_FILENO, devnull); |
45 | close(devnull); | ||
45 | uint8_t success = 0; | 46 | uint8_t success = 0; |
46 | if (chdir("/") != 0) { | 47 | if (chdir("/") != 0) { |
47 | write(fds[1], &success, 1); | 48 | write(fds[1], &success, 1); |