From bfde7f2d04fbb22e26c9eb843e4ccc478762dd8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Wed, 10 May 2023 14:50:24 +0200 Subject: [PATCH] Initialize automaticly freed variables where the function could return before the first assignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 13.1.1 warned on some places like this: In file included from /usr/include/glib-2.0/glib.h:117, from ../modulemd/modulemd-translation-entry.c:14: In function ‘g_autoptr_cleanup_generic_gfree’, inlined from ‘modulemd_translation_entry_parse_yaml’ at ../modulemd/modulemd-translation-entry.c:39 8:21: /usr/include/glib-2.0/glib/glib-autocleanups.h:30:3: warning: ‘value’ may be used uninitialized [-Wmaybe-uninitialized] 30 | g_free (*pp); | ^~~~~~~~~~~~ ../modulemd/modulemd-translation-entry.c: In function ‘modulemd_translation_entry_parse_yaml’: ../modulemd/modulemd-translation-entry.c:398:21: note: ‘value’ was declared here 398 | g_autofree gchar *value; | ^~~~~ Automatic variables with a cleanup attribute are automatically deinicialized when they go out of scope, but they are not automatically initialized when defined. This patch adds the missing initialization. --- modulemd/modulemd-translation-entry.c | 2 +- modulemd/tests/test-modulemd-profile.c | 2 +- modulemd/tests/test-modulemd-translation-entry.c | 6 +++--- modulemd/tests/test-modulemd-translation.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modulemd/modulemd-translation-entry.c b/modulemd/modulemd-translation-entry.c index b800a1f1..7bac5905 100644 --- a/modulemd/modulemd-translation-entry.c +++ b/modulemd/modulemd-translation-entry.c @@ -395,7 +395,7 @@ modulemd_translation_entry_parse_yaml (yaml_parser_t *parser, MMD_INIT_YAML_EVENT (event); gboolean done = FALSE; gboolean in_map = FALSE; - g_autofree gchar *value; + g_autofree gchar *value = NULL; GHashTable *profiles = NULL; g_autoptr (ModulemdTranslationEntry) te = NULL; g_autoptr (GError) nested_error = NULL; diff --git a/modulemd/tests/test-modulemd-profile.c b/modulemd/tests/test-modulemd-profile.c index 93e11ad7..3a730c16 100644 --- a/modulemd/tests/test-modulemd-profile.c +++ b/modulemd/tests/test-modulemd-profile.c @@ -38,7 +38,7 @@ static void profile_test_construct (void) { g_autoptr (ModulemdProfile) p = NULL; - g_auto (GStrv) rpms; + g_auto (GStrv) rpms = NULL; /* Test that the new() function works */ p = modulemd_profile_new ("testprofile"); diff --git a/modulemd/tests/test-modulemd-translation-entry.c b/modulemd/tests/test-modulemd-translation-entry.c index 342aa852..858bdfa8 100644 --- a/modulemd/tests/test-modulemd-translation-entry.c +++ b/modulemd/tests/test-modulemd-translation-entry.c @@ -38,7 +38,7 @@ static void translation_entry_test_construct (void) { g_autoptr (ModulemdTranslationEntry) te = NULL; - g_auto (GStrv) profile_names; + g_auto (GStrv) profile_names = NULL; /* Test that the new() function works */ te = modulemd_translation_entry_new ("en_US"); @@ -146,7 +146,7 @@ translation_entry_test_copy (void) { g_autoptr (ModulemdTranslationEntry) te = NULL; g_autoptr (ModulemdTranslationEntry) te_copy = NULL; - g_auto (GStrv) profile_names; + g_auto (GStrv) profile_names = NULL; /* Test copying an empty translation entry */ te = modulemd_translation_entry_new ("en_GB"); @@ -426,7 +426,7 @@ static void translation_entry_test_profile_descriptions (void) { g_autoptr (ModulemdTranslationEntry) te = NULL; - g_auto (GStrv) profile_names; + g_auto (GStrv) profile_names = NULL; te = modulemd_translation_entry_new ("en_US"); g_assert_nonnull (te); diff --git a/modulemd/tests/test-modulemd-translation.c b/modulemd/tests/test-modulemd-translation.c index 7f2263f3..655200f9 100644 --- a/modulemd/tests/test-modulemd-translation.c +++ b/modulemd/tests/test-modulemd-translation.c @@ -43,7 +43,7 @@ static void translation_test_construct (void) { g_autoptr (ModulemdTranslation) t = NULL; - g_auto (GStrv) locales; + g_auto (GStrv) locales = NULL; guint64 translation_version = 1; guint64 modified = 3; @@ -137,7 +137,7 @@ translation_test_copy (void) g_autoptr (ModulemdTranslation) t = NULL; g_autoptr (ModulemdTranslation) t_copy = NULL; ModulemdTranslationEntry *te = NULL; - g_auto (GStrv) locales; + g_auto (GStrv) locales = NULL; t = modulemd_translation_new (1, "testmod", "teststr", 5); g_assert_nonnull (t);