Skip to content

Commit bfde7f2

Browse files
committed
Initialize automaticly freed variables where the function could return before the first assignment
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.
1 parent 9f0c090 commit bfde7f2

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

modulemd/modulemd-translation-entry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ modulemd_translation_entry_parse_yaml (yaml_parser_t *parser,
395395
MMD_INIT_YAML_EVENT (event);
396396
gboolean done = FALSE;
397397
gboolean in_map = FALSE;
398-
g_autofree gchar *value;
398+
g_autofree gchar *value = NULL;
399399
GHashTable *profiles = NULL;
400400
g_autoptr (ModulemdTranslationEntry) te = NULL;
401401
g_autoptr (GError) nested_error = NULL;

modulemd/tests/test-modulemd-profile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void
3838
profile_test_construct (void)
3939
{
4040
g_autoptr (ModulemdProfile) p = NULL;
41-
g_auto (GStrv) rpms;
41+
g_auto (GStrv) rpms = NULL;
4242

4343
/* Test that the new() function works */
4444
p = modulemd_profile_new ("testprofile");

modulemd/tests/test-modulemd-translation-entry.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void
3838
translation_entry_test_construct (void)
3939
{
4040
g_autoptr (ModulemdTranslationEntry) te = NULL;
41-
g_auto (GStrv) profile_names;
41+
g_auto (GStrv) profile_names = NULL;
4242

4343
/* Test that the new() function works */
4444
te = modulemd_translation_entry_new ("en_US");
@@ -146,7 +146,7 @@ translation_entry_test_copy (void)
146146
{
147147
g_autoptr (ModulemdTranslationEntry) te = NULL;
148148
g_autoptr (ModulemdTranslationEntry) te_copy = NULL;
149-
g_auto (GStrv) profile_names;
149+
g_auto (GStrv) profile_names = NULL;
150150

151151
/* Test copying an empty translation entry */
152152
te = modulemd_translation_entry_new ("en_GB");
@@ -426,7 +426,7 @@ static void
426426
translation_entry_test_profile_descriptions (void)
427427
{
428428
g_autoptr (ModulemdTranslationEntry) te = NULL;
429-
g_auto (GStrv) profile_names;
429+
g_auto (GStrv) profile_names = NULL;
430430

431431
te = modulemd_translation_entry_new ("en_US");
432432
g_assert_nonnull (te);

modulemd/tests/test-modulemd-translation.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static void
4343
translation_test_construct (void)
4444
{
4545
g_autoptr (ModulemdTranslation) t = NULL;
46-
g_auto (GStrv) locales;
46+
g_auto (GStrv) locales = NULL;
4747
guint64 translation_version = 1;
4848
guint64 modified = 3;
4949

@@ -137,7 +137,7 @@ translation_test_copy (void)
137137
g_autoptr (ModulemdTranslation) t = NULL;
138138
g_autoptr (ModulemdTranslation) t_copy = NULL;
139139
ModulemdTranslationEntry *te = NULL;
140-
g_auto (GStrv) locales;
140+
g_auto (GStrv) locales = NULL;
141141

142142
t = modulemd_translation_new (1, "testmod", "teststr", 5);
143143
g_assert_nonnull (t);

0 commit comments

Comments
 (0)