From 9bc69fd715b8bb45c0c45a27c71ce2cc49b0c7d3 Mon Sep 17 00:00:00 2001 From: rbuj Date: Mon, 21 Dec 2020 15:39:17 +0100 Subject: Remove cppcheck warnings about the variable scope can be reduced --- lib/sensors-applet-plugin.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/sensors-applet-plugin.c b/lib/sensors-applet-plugin.c index acef5ef..f1476d1 100644 --- a/lib/sensors-applet-plugin.c +++ b/lib/sensors-applet-plugin.c @@ -32,10 +32,6 @@ extern const gchar *plugin_name; void sensors_applet_plugin_find_sensors(GList **sensors, const gchar *path, SensorsAppletPluginTestSensorFunc test_sensor) { - GDir *dir; - const gchar* new_file; - gchar *new_path; - if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { /* also test can actually open file for reading */ if (access(path, R_OK) == 0) { @@ -48,9 +44,14 @@ void sensors_applet_plugin_find_sensors(GList **sensors, for a sensor dir */ if (g_file_test(path, G_FILE_TEST_IS_DIR) && !g_file_test(path, G_FILE_TEST_IS_SYMLINK)) { - dir = g_dir_open(path, 0, NULL); - if (dir != NULL) { + GDir *dir; + + if ((dir = g_dir_open(path, 0, NULL)) != NULL) { + const gchar *new_file; + while(NULL != (new_file = g_dir_read_name(dir))) { + gchar *new_path; + new_path = g_build_filename(path, new_file, NULL); sensors_applet_plugin_find_sensors(sensors, new_path, test_sensor); g_free(new_path); @@ -63,9 +64,10 @@ void sensors_applet_plugin_find_sensors(GList **sensors, /* for error handling */ GQuark sensors_applet_plugin_error_quark(void) { static GQuark quark = 0; - gchar *string; if (quark == 0) { + gchar *string; + string = g_strdup_printf("%s-plugin-error", plugin_name); quark = g_quark_from_string(string); g_free(string); -- cgit v1.2.1