diff options
Diffstat (limited to 'src/libnm-glib-aux/nm-uuid.c')
| -rw-r--r-- | src/libnm-glib-aux/nm-uuid.c | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c index 464bbf58..53e8b78c 100644 --- a/src/libnm-glib-aux/nm-uuid.c +++ b/src/libnm-glib-aux/nm-uuid.c @@ -202,28 +202,25 @@ nm_uuid_is_valid_nm(const char *str, /* @out_normalized_str is only set, if normalization was necessary * and possible. The caller cannot request @out_normalized_str, without - * also getting @out_normalized. */ + * also requesting @out_normalized. Otherwise, they couldn't know whether + * a normalized string was returned. */ nm_assert(!out_normalized_str || out_normalized); if (!str) return FALSE; if (nm_uuid_parse_full(str, &uuid, &is_normalized)) { - /* Note that: - * @is_normalized means that "str" contains a normalized UUID - * @out_normalized: indicates whether str requires normalization - * and whether @out_normalized_str was set to contain the normalized - * UUID. - * With this, we get the slightly odd assignment: */ - NM_SET_OUT(out_normalized, !is_normalized); - - if (!is_normalized && out_normalized_str) { - /* we need to normalize the UUID */ - nm_uuid_unparse(&uuid, out_normalized_str); + if (is_normalized) { + /* @str is already normalized. No need to normalize again, so + * @out_normalized is FALSE. */ + NM_SET_OUT(out_normalized, FALSE); + } else { + NM_SET_OUT(out_normalized, TRUE); + if (out_normalized_str) { + /* we need to normalize the UUID */ + nm_uuid_unparse(&uuid, out_normalized_str); + } } - - /* regardless whether normalization was necessary, the UUID is - * essentially valid. */ return TRUE; } @@ -235,24 +232,23 @@ nm_uuid_is_valid_nm(const char *str, * are made lower case first. */ NM_SET_OUT(out_normalized, TRUE); if (out_normalized_str) { - char str_lower[40 + 1]; + char str_lower[40]; int i; - nm_assert(strlen(str) < G_N_ELEMENTS(str_lower)); + nm_assert(strlen(str) <= G_N_ELEMENTS(str_lower)); /* normalize first to lower-case. */ for (i = 0; str[i]; i++) { nm_assert(i < G_N_ELEMENTS(str_lower)); str_lower[i] = g_ascii_tolower(str[i]); } - nm_assert(i < G_N_ELEMENTS(str_lower)); - str_lower[i] = '\0'; + nm_assert(i <= G_N_ELEMENTS(str_lower)); /* The namespace UUID is chosen randomly. */ nm_uuid_generate_from_string( &uuid, str_lower, - -1, + i, NM_UUID_TYPE_VERSION5, &NM_UUID_INIT(4e, 72, f7, 09, ca, 95, 44, 05, 90, 53, 1f, 43, 29, 4a, 61, 8c)); nm_uuid_unparse(&uuid, out_normalized_str); |