mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-06 06:10:14 +01:00
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 2386c0f52d)
This commit is contained in:
parent
15ffa8ec6f
commit
cbf20a2317
1 changed files with 2 additions and 2 deletions
|
|
@ -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]) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue