From cbf20a23172944357d2dfa7726956c20e61738fe Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 3 Apr 2024 14:02:33 +0200 Subject: [PATCH] libnm-glib-aux: fix "maybe-uninitialized" error when generating UUID GCC 14 complans with: src/libnm-glib-aux/nm-uuid.c: In function 'nm_uuid_generate_from_strings_strv': src/libnm-glib-aux/nm-uuid.c:492:12: error: '_1' may be used uninitialized [-Werror=maybe-uninitialized] 492 | return nm_uuid_generate_from_string_str(s, slen, uuid_type, type_args); | ^ src/libnm-glib-aux/nm-uuid.c:392:1: note: by argument 1 of type 'const char *' to 'nm_uuid_generate_from_string_str' declared here 392 | nm_uuid_generate_from_string_str(const char *s, | ^ "-Wmaybe-uninitialized" diagnoses passing pointers or references to uninitialized memory to functions taking const-qualified arguments. In this case, nm_uuid_generate_from_string_str()'s first argument is a "const char *" and so the compiler expects that the string is always initialized. However, it is not initialized when len is zero. A non-null zero-length array can be specified in two ways: by setting len to zero, or by setting len to -1 and having NULL as first element. Handle both cases in the same way. (cherry picked from commit 2386c0f52d07ebc3dac1441124d3cd6099d18384) --- src/libnm-glib-aux/nm-uuid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c index df1b10c0ac..ff13c8fb11 100644 --- a/src/libnm-glib-aux/nm-uuid.c +++ b/src/libnm-glib-aux/nm-uuid.c @@ -436,7 +436,7 @@ nm_uuid_generate_from_strings_strv(NMUuidType uuid_type, gsize slen; const char *s; - if (len >= 0) { + if (len > 0) { gboolean has_nulls = FALSE; gssize i; @@ -471,7 +471,7 @@ nm_uuid_generate_from_strings_strv(NMUuidType uuid_type, * in the other cases). */ slen = 1; s = "x"; - } else if (!strv[0]) { + } else if (!strv[0] || len == 0) { slen = 0; s = ""; } else if (!strv[1]) {