From 726192c185de74d799cf7bdce5caaa26a29e6b61 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 18 Jul 2019 16:04:16 +0200 Subject: [PATCH] libnm: accept %NULL for @name argument of nm_utils_is_valid_iface_name() Rejecting %NULL for a "is-a" function can be annoying. Of course, %NULL is not a valid name. But it's sufficient that the function just returns %FALSE in that case, and not assert against the input not being %NULL. Asserting might be useful to catch bugs, but rejecting %NULL as input is more cumbersome to the caller than helping with catching bugs. Something similar was also recently done for nm_utils_is_uuid(). --- libnm-core/nm-utils.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 6dc3f53dd3..68da624818 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -4660,7 +4660,7 @@ nm_utils_is_valid_iface_name_utf8safe (const char *utf8safe_name) /** * nm_utils_is_valid_iface_name: - * @name: Name of interface + * @name: (allow-none): Name of interface * @error: location to store the error occurring, or %NULL to ignore * * Validate the network interface name. @@ -4669,13 +4669,20 @@ nm_utils_is_valid_iface_name_utf8safe (const char *utf8safe_name) * function in net/core/dev.c. * * Returns: %TRUE if interface name is valid, otherwise %FALSE is returned. + * + * Before 1.20, this function did not accept %NULL as @name argument. If you + * want to run against older versions of libnm, don't pass %NULL. */ gboolean nm_utils_is_valid_iface_name (const char *name, GError **error) { int i; - g_return_val_if_fail (name, FALSE); + if (!name) { + g_set_error_literal (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, + _("interface name is missing")); + return FALSE; + } if (name[0] == '\0') { g_set_error_literal (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, @@ -4712,13 +4719,16 @@ nm_utils_is_valid_iface_name (const char *name, GError **error) /** * nm_utils_iface_valid_name: - * @name: Name of interface + * @name: (allow-none): Name of interface * * Validate the network interface name. * * Deprecated: 1.6: use nm_utils_is_valid_iface_name() instead, with better error reporting. * * Returns: %TRUE if interface name is valid, otherwise %FALSE is returned. + * + * Before 1.20, this function did not accept %NULL as @name argument. If you + * want to run against older versions of libnm, don't pass %NULL. */ gboolean nm_utils_iface_valid_name (const char *name)