mirror of
https://github.com/swaywm/sway.git
synced 2024-11-23 08:21:28 +00:00
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.
This commit is contained in:
parent
e67c8cf1cb
commit
248ea93c1a
|
@ -70,16 +70,12 @@ void free_bar_config(struct bar_config *bar) {
|
||||||
|
|
||||||
struct bar_config *default_bar_config(void) {
|
struct bar_config *default_bar_config(void) {
|
||||||
struct bar_config *bar = NULL;
|
struct bar_config *bar = NULL;
|
||||||
bar = malloc(sizeof(struct bar_config));
|
bar = calloc(1, sizeof(struct bar_config));
|
||||||
if (!bar) {
|
if (!bar) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!(bar->mode = strdup("dock"))) goto cleanup;
|
|
||||||
if (!(bar->hidden_state = strdup("hide"))) goto cleanup;
|
|
||||||
bar->outputs = NULL;
|
bar->outputs = NULL;
|
||||||
bar->position = strdup("bottom");
|
bar->position = strdup("bottom");
|
||||||
if (!(bar->bindings = create_list())) goto cleanup;
|
|
||||||
if (!(bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p'; sleep 1; done"))) goto cleanup;
|
|
||||||
bar->pango_markup = false;
|
bar->pango_markup = false;
|
||||||
bar->swaybar_command = NULL;
|
bar->swaybar_command = NULL;
|
||||||
bar->font = NULL;
|
bar->font = NULL;
|
||||||
|
@ -91,6 +87,19 @@ struct bar_config *default_bar_config(void) {
|
||||||
bar->binding_mode_indicator = true;
|
bar->binding_mode_indicator = true;
|
||||||
bar->verbose = false;
|
bar->verbose = false;
|
||||||
bar->pid = 0;
|
bar->pid = 0;
|
||||||
|
if (!(bar->mode = strdup("dock"))) {
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (!(bar->hidden_state = strdup("hide"))) {
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (!(bar->bindings = create_list())) {
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (!(bar->status_command =
|
||||||
|
strdup("while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done"))) {
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
// set default colors
|
// set default colors
|
||||||
if (!(bar->colors.background = strndup("#000000ff", 9))) {
|
if (!(bar->colors.background = strndup("#000000ff", 9))) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
Loading…
Reference in a new issue