config: add cleanup and warnings for config parsing edge cases
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ifd08f33a0e6cc6e4f49966ea1c3f03f56a6a6964
This commit is contained in:
parent
edae535674
commit
f032d3723d
1 changed files with 10 additions and 8 deletions
18
src/config.c
18
src/config.c
|
|
@ -232,6 +232,7 @@ int chroma_config_load_toml(chroma_config_t *config, const char *config_file) {
|
|||
toml_result_t result = toml_parse_file_ex(config_file);
|
||||
if (!result.ok) {
|
||||
chroma_log("DEBUG", "TOML parse failed: %s", result.errmsg);
|
||||
toml_free(result);
|
||||
return CHROMA_ERROR_CONFIG;
|
||||
}
|
||||
|
||||
|
|
@ -244,6 +245,12 @@ int chroma_config_load_toml(chroma_config_t *config, const char *config_file) {
|
|||
const char *path_to_use = expanded_path ? expanded_path : default_image.u.s;
|
||||
if (strlen(path_to_use) < sizeof(config->default_image)) {
|
||||
strcpy(config->default_image, path_to_use);
|
||||
} else {
|
||||
chroma_log("WARN",
|
||||
"default_image path too long (%zu >= %zu), truncating: %s",
|
||||
strlen(path_to_use), sizeof(config->default_image), path_to_use);
|
||||
snprintf(config->default_image, sizeof(config->default_image), "%s",
|
||||
path_to_use);
|
||||
}
|
||||
if (expanded_path) {
|
||||
free(expanded_path);
|
||||
|
|
@ -427,14 +434,9 @@ static void init_default_config(chroma_config_t *config) {
|
|||
config->max_output_height = 2160; // 4K height
|
||||
config->min_scale_factor = 0.25f; // don't scale below 25%
|
||||
|
||||
// Set default image path (can be overridden)
|
||||
const char *home = getenv("HOME");
|
||||
if (home) {
|
||||
snprintf(config->default_image, sizeof(config->default_image),
|
||||
"%s/.config/chroma/default.jpg", home);
|
||||
} else {
|
||||
strcpy(config->default_image, "/usr/share/pixmaps/chroma-default.jpg");
|
||||
}
|
||||
// Leave default_image empty - user must configure it explicitly
|
||||
// This avoids errors when the hardcoded path doesn't exist
|
||||
config->default_image[0] = '\0';
|
||||
}
|
||||
|
||||
// Load configuration from file (TOML format only)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue