From 873bd6973dd08ebb8a0fc24417e1bfa0990eefee Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Tue, 7 May 2024 09:50:07 +0200 Subject: [PATCH] Fix shadow variables --- src/configfile.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/configfile.c b/src/configfile.c index 3390b34..5d43b61 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -353,6 +353,9 @@ static int config_file_resolve(void) void config_file_show_profiles(void) { + GKeyFile *keyfile; + GError *error = NULL; + memset(&config, 0, sizeof(struct config_t)); // Find config file @@ -362,9 +365,6 @@ void config_file_show_profiles(void) return; } - GKeyFile *keyfile; - GError *error = NULL; - keyfile = g_key_file_new(); if (!g_key_file_load_from_file(keyfile, config.path, G_KEY_FILE_NONE, &error)) @@ -458,10 +458,10 @@ static char *match_and_replace(const char *str, const char *pattern, char *devic { tio_debug_printf("Subexpression %d match: ", i); int k = 0; - for (int j = matches[i].rm_so; j < matches[i].rm_eo; j++) + for (int l = matches[i].rm_so; l < matches[i].rm_eo; l++) { - tio_debug_printf_raw("%c", str[j]); - replacement_str[k++] = str[j]; + tio_debug_printf_raw("%c", str[l]); + replacement_str[k++] = str[l]; } replacement_str[k] = '\0'; sprintf(m_key, "%%m%d", i); @@ -541,11 +541,11 @@ void config_file_parse(void) } // Lookup 'pattern' key - GError *error = NULL; gchar *pattern = g_key_file_get_string(keyfile, group[i], "pattern", &error); if (error != NULL) { g_error_free(error); + error = NULL; continue; } @@ -554,6 +554,7 @@ void config_file_parse(void) if (error != NULL) { g_error_free(error); + error = NULL; continue; } @@ -564,14 +565,14 @@ void config_file_parse(void) if (config.device != NULL) { // Match found - save device - char *device = strdup(config.device); + device = strdup(config.device); - // Parse found group + // Parse found group (may replace config.device) config_parse_keys(keyfile, group[i]); // Update configuration config.active_group = strdup(group[i]); - config.device = device; + config.device = device; // Restore new device string break; }