From 796ba8dcd10b3172c9d1de2efc74e07a3becc982 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 21 Jan 2022 10:40:00 +0100 Subject: [PATCH] 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. (cherry picked from commit cb9ca67901b3575711707f21a6f2d97a7de36e9a) (cherry picked from commit 634e023e72d4729788a022ea1fae665af28d1b0f) --- src/libnm-glib-aux/nm-uuid.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c index 2c6e218a7c..178f97f182 100644 --- a/src/libnm-glib-aux/nm-uuid.c +++ b/src/libnm-glib-aux/nm-uuid.c @@ -382,9 +382,15 @@ nm_uuid_generate_from_string_str(const char *s, NMUuidType uuid_type, gpointer 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)); }