1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2025-04-07 17:44:04 -04:00

options: fix segfault on start

struct options::all_scripts is not initialized if no config file is
being used. Later if fading is enable on the command line, we will
try to push into a NULL dynarr.

Make sure all_scripts is always initialized.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2024-06-13 07:48:40 +01:00
parent 7befeffc6d
commit 68cb38368c
No known key found for this signature in database
GPG key ID: D3A4405BE6CC17F4
2 changed files with 7 additions and 9 deletions

View file

@ -22,6 +22,7 @@
#include "common.h"
#include "log.h"
#include "utils/dynarr.h"
#include "utils/kernel.h"
#include "utils/str.h"
@ -719,5 +720,6 @@ bool parse_config(options_t *opt, const char *config_file) {
// clang-format on
list_init_head(&opt->included_config_files);
opt->all_scripts = dynarr_new(struct script *, 4);
return parse_config_libconfig(opt, config_file);
}

View file

@ -387,18 +387,17 @@ parse_animation_one(struct win_script *animations, config_setting_t *setting) {
return script;
}
static struct script **
parse_animations(struct win_script *animations, config_setting_t *setting) {
/// `out_scripts`: all the script objects created, this is a dynarr.
static void parse_animations(struct win_script *animations, config_setting_t *setting,
struct script ***out_scripts) {
auto number_of_animations = (unsigned)config_setting_length(setting);
auto all_scripts = dynarr_new(struct script *, number_of_animations + 1);
for (unsigned i = 0; i < number_of_animations; i++) {
auto sub = config_setting_get_elem(setting, (unsigned)i);
auto script = parse_animation_one(animations, sub);
if (script != NULL) {
dynarr_push(all_scripts, script);
dynarr_push(*out_scripts, script);
}
}
return all_scripts;
}
#define FADING_TEMPLATE_1 \
@ -975,10 +974,7 @@ bool parse_config_libconfig(options_t *opt, const char *config_file) {
config_setting_t *animations = config_lookup(&cfg, "animations");
if (animations) {
opt->all_scripts = parse_animations(opt->animations, animations);
} else {
// Reserve some space for generated fading scripts.
opt->all_scripts = dynarr_new(struct script *, 4);
parse_animations(opt->animations, animations, &opt->all_scripts);
}
opt->config_file_path = path;