glib-aux: workaround maybe-uninitialized warning with LTO in nm_uuid_generate_from_string_str()

In function 'nm_uuid_unparse',
      inlined from 'nm_uuid_generate_from_string_str' at src/libnm-glib-aux/nm-uuid.c:393:12,
      inlined from 'nm_uuid_generate_from_strings.constprop' at src/libnm-glib-aux/nm-uuid.c:430:16:
  src/libnm-glib-aux/nm-uuid.h:37:12: error: 'uuid' may be used uninitialized [-Werror=maybe-uninitialized]
     37 |     return nm_uuid_unparse_case(uuid, out_str, FALSE);
        |            ^
  src/libnm-glib-aux/nm-uuid.c: In function 'nm_uuid_generate_from_strings.constprop':
  src/libnm-glib-aux/nm-uuid.c:20:1: note: by argument 1 of type 'const struct NMUuid *' to 'nm_uuid_unparse_case.constprop' declared here
     20 | nm_uuid_unparse_case(const NMUuid *uuid, char out_str[static 37], gboolean upper_case)
        | ^
  src/libnm-glib-aux/nm-uuid.c:390:12: note: 'uuid' declared here
    390 |     NMUuid uuid;
        |            ^
  lto1: all warnings being treated as errors

The problem are code paths with failed g_return*() assertions. Being in
a bad state already, they don't bother to ensure proper return values,
and with LTO the compiler might think there are valid code paths wrongly
handled. Work around.
This commit is contained in:
Thomas Haller
2022-01-21 10:40:00 +01:00
parent 3dd854eb1b
commit cb9ca67901

View File

@@ -387,9 +387,15 @@ nm_uuid_generate_from_string_str(const char *s,
NMUuidType uuid_type,
const NMUuid *type_args)
{
NMUuid uuid;
NMUuid uuid;
const NMUuid *u;
u = nm_uuid_generate_from_string(&uuid, s, slen, uuid_type, type_args);
if (G_UNLIKELY(!u))
return nm_assert_unreachable_val(NULL);
nm_assert(u == &uuid);
nm_uuid_generate_from_string(&uuid, s, slen, uuid_type, type_args);
return nm_uuid_unparse(&uuid, g_new(char, 37));
}