Skip to content

Commit

Permalink
Initialize automaticly freed variables where the function could retur…
Browse files Browse the repository at this point in the history
…n 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.
  • Loading branch information
ppisar committed May 10, 2023
1 parent 9f0c090 commit bfde7f2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion modulemd/modulemd-translation-entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion modulemd/tests/test-modulemd-profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions modulemd/tests/test-modulemd-translation-entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions modulemd/tests/test-modulemd-translation.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bfde7f2

Please sign in to comment.