diff --git a/src/config.c b/src/config.c index d082249..e9c615e 100644 --- a/src/config.c +++ b/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)