summaryrefslogtreecommitdiffstats
path: root/sway/config
diff options
context:
space:
mode:
authorLibravatar Dominique Martinet <asmadeus@codewreck.org>2018-07-01 23:22:21 +0900
committerLibravatar Dominique Martinet <asmadeus@codewreck.org>2018-07-02 08:03:41 +0900
commit248ea93c1af7eae5a57c354b0e2e50898f57b17d (patch)
tree813f482d8b60c005cda6968223ff132397040859 /sway/config
parentcmd_assign: fix leak on error (diff)
downloadsway-248ea93c1af7eae5a57c354b0e2e50898f57b17d.tar.gz
sway-248ea93c1af7eae5a57c354b0e2e50898f57b17d.tar.zst
sway-248ea93c1af7eae5a57c354b0e2e50898f57b17d.zip
bar config: fix uninitialized accesses on init error
If init fails halfway through it will call the destroy function, which needs some coherent stuff filled. Allocate with calloc and fill in what cannot fail first Found through static analysis.
Diffstat (limited to 'sway/config')
-rw-r--r--sway/config/bar.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/sway/config/bar.c b/sway/config/bar.c
index e790c911..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
71struct bar_config *default_bar_config(void) { 71struct 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;