[libnma/ac/release: 2/3] all: end strlen() abuse




commit 96575d2e5e1953d988797255eaab474a14df487e
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Fri Jan 21 12:00:13 2022 +0100

    all: end strlen() abuse
    
    Let's not use strlen() to check for zero-length strings. Just take a
    peek at the first character to check if it's NUL.
    
    This doesn't fix an actual issue, merely makes things more consistent
    and perhaps spares a few cpu cycles in case compiler can't see through
    what we're doing.

 src/nma-mobile-providers.c  | 2 +-
 src/nma-mobile-wizard.c     | 4 ++--
 src/nma-ws/nma-eap-fast.c   | 2 +-
 src/nma-ws/nma-eap-leap.c   | 4 ++--
 src/nma-ws/nma-eap-peap.c   | 4 ++--
 src/nma-ws/nma-eap-simple.c | 6 +++---
 src/nma-ws/nma-eap-tls.c    | 2 +-
 src/nma-ws/nma-eap-ttls.c   | 4 ++--
 src/nma-ws/nma-ws-leap.c    | 4 ++--
 src/utils/utils.c           | 6 +++---
 10 files changed, 19 insertions(+), 19 deletions(-)
---
diff --git a/src/nma-mobile-providers.c b/src/nma-mobile-providers.c
index 743f3ff5..95f352f4 100644
--- a/src/nma-mobile-providers.c
+++ b/src/nma-mobile-providers.c
@@ -611,7 +611,7 @@ parser_gsm_start (MobileParser *parser,
                        else if (!strcmp (attribute_names[i], "mnc"))
                                mnc = attribute_values[i];
 
-                       if (mcc && strlen (mcc) && mnc && strlen (mnc)) {
+                       if (mcc && *mcc && mnc && *mnc) {
                                gchar *mccmnc;
 
                                if (!parser->current_provider->mcc_mnc)
diff --git a/src/nma-mobile-wizard.c b/src/nma-mobile-wizard.c
index 816ac437..11ee6065 100644
--- a/src/nma-mobile-wizard.c
+++ b/src/nma-mobile-wizard.c
@@ -350,7 +350,7 @@ plan_update_complete (NMAMobileWizard *self)
 
                manual_apn = gtk_editable_get_text (priv->plan_apn_entry);
                gtk_assistant_set_page_complete (priv->assistant, priv->plan_page,
-                                                (manual_apn && strlen (manual_apn)));
+                                                (manual_apn && *manual_apn));
        }
 }
 
@@ -1361,7 +1361,7 @@ get_country_from_locale (void)
                return NULL;
 
        p = strchr (lang, '_');
-       if (!p || !strlen (p)) {
+       if (!p || !*p) {
                g_free (p);
                return NULL;
        }
diff --git a/src/nma-ws/nma-eap-fast.c b/src/nma-ws/nma-eap-fast.c
index d2cbee11..c5f9c2ac 100644
--- a/src/nma-ws/nma-eap-fast.c
+++ b/src/nma-ws/nma-eap-fast.c
@@ -134,7 +134,7 @@ fill_connection (NMAEap *parent, NMConnection *connection)
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_fast_anon_identity_entry"));
        g_assert (widget);
        text = gtk_editable_get_text (GTK_EDITABLE (widget));
-       if (text && strlen (text))
+       if (text && *text)
                g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, text, NULL);
 
        g_object_set (s_8021x, NM_SETTING_802_1X_PAC_FILE, method->pac_file_name, NULL);
diff --git a/src/nma-ws/nma-eap-leap.c b/src/nma-ws/nma-eap-leap.c
index 4a577f0d..0702ea56 100644
--- a/src/nma-ws/nma-eap-leap.c
+++ b/src/nma-ws/nma-eap-leap.c
@@ -50,7 +50,7 @@ validate (NMAEap *parent, GError **error)
        gboolean ret = TRUE;
 
        text = gtk_editable_get_text (GTK_EDITABLE (method->username_entry));
-       if (!text || !strlen (text)) {
+       if (!text || !*text) {
                widget_set_error (GTK_WIDGET (method->username_entry));
                g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing EAP-LEAP username"));
                ret = FALSE;
@@ -58,7 +58,7 @@ validate (NMAEap *parent, GError **error)
                widget_unset_error (GTK_WIDGET (method->username_entry));
 
        text = gtk_editable_get_text (GTK_EDITABLE (method->password_entry));
-       if (!text || !strlen (text)) {
+       if (!text || !*text) {
                widget_set_error (GTK_WIDGET (method->password_entry));
                if (ret) {
                        g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing EAP-LEAP 
password"));
diff --git a/src/nma-ws/nma-eap-peap.c b/src/nma-ws/nma-eap-peap.c
index 831abf91..37fbb0a3 100644
--- a/src/nma-ws/nma-eap-peap.c
+++ b/src/nma-ws/nma-eap-peap.c
@@ -143,13 +143,13 @@ fill_connection (NMAEap *parent, NMConnection *connection)
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_peap_anon_identity_entry"));
        g_assert (widget);
        text = gtk_editable_get_text (GTK_EDITABLE (widget));
-       if (text && strlen (text))
+       if (text && *text)
                g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, text, NULL);
 
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_peap_domain_entry"));
        g_assert (widget);
        text = gtk_editable_get_text (GTK_EDITABLE (widget));
-       if (text && strlen (text))
+       if (text && *text)
                g_object_set (s_8021x, NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH, text, NULL);
 
        /* Save CA certificate PIN and its flags to the connection */
diff --git a/src/nma-ws/nma-eap-simple.c b/src/nma-ws/nma-eap-simple.c
index fb0bae11..279a8785 100644
--- a/src/nma-ws/nma-eap-simple.c
+++ b/src/nma-ws/nma-eap-simple.c
@@ -74,7 +74,7 @@ validate (NMAEap *parent, GError **error)
 
        if (method->username_requested) {
                text = gtk_editable_get_text (GTK_EDITABLE (method->username_entry));
-               if (!text || !strlen (text)) {
+               if (!text || !*text) {
                        widget_set_error (GTK_WIDGET (method->username_entry));
                        g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing EAP username"));
                        ret = FALSE;
@@ -88,7 +88,7 @@ validate (NMAEap *parent, GError **error)
                        widget_unset_error (GTK_WIDGET (method->password_entry));
                else {
                        text = gtk_editable_get_text (GTK_EDITABLE (method->password_entry));
-                       if (!text || !strlen (text)) {
+                       if (!text || !*text) {
                                widget_set_error (GTK_WIDGET (method->password_entry));
                                if (ret) {
                                        g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC,
@@ -102,7 +102,7 @@ validate (NMAEap *parent, GError **error)
 
        if (method->pkey_passphrase_requested) {
                text = gtk_editable_get_text (GTK_EDITABLE (method->pkey_passphrase_entry));
-               if (!text || !strlen (text)) {
+               if (!text || !*text) {
                        widget_set_error (GTK_WIDGET (method->pkey_passphrase_entry));
                        if (ret) {
                                g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC,
diff --git a/src/nma-ws/nma-eap-tls.c b/src/nma-ws/nma-eap-tls.c
index 5b6f1044..070fea07 100644
--- a/src/nma-ws/nma-eap-tls.c
+++ b/src/nma-ws/nma-eap-tls.c
@@ -42,7 +42,7 @@ validate (NMAEap *parent, GError **error)
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_tls_identity_entry"));
        g_assert (widget);
        identity = gtk_editable_get_text (GTK_EDITABLE (widget));
-       if (!identity || !strlen (identity)) {
+       if (!identity || !*identity) {
                widget_set_error (widget);
                g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing EAP-TLS identity"));
                return FALSE;
diff --git a/src/nma-ws/nma-eap-ttls.c b/src/nma-ws/nma-eap-ttls.c
index 06b808bc..aceab4eb 100644
--- a/src/nma-ws/nma-eap-ttls.c
+++ b/src/nma-ws/nma-eap-ttls.c
@@ -139,13 +139,13 @@ fill_connection (NMAEap *parent, NMConnection *connection)
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_ttls_anon_identity_entry"));
        g_assert (widget);
        text = gtk_editable_get_text (GTK_EDITABLE (widget));
-       if (text && strlen (text))
+       if (text && *text)
                g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, text, NULL);
 
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_ttls_domain_entry"));
        g_assert (widget);
        text = gtk_editable_get_text (GTK_EDITABLE (widget));
-       if (text && strlen (text))
+       if (text && *text)
                g_object_set (s_8021x, NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH, text, NULL);
 
        /* Save CA certificate PIN and its flags to the connection */
diff --git a/src/nma-ws/nma-ws-leap.c b/src/nma-ws/nma-ws-leap.c
index a919e7e1..c3d09854 100644
--- a/src/nma-ws/nma-ws-leap.c
+++ b/src/nma-ws/nma-ws-leap.c
@@ -66,7 +66,7 @@ validate (NMAWs *ws, GError **error)
        gboolean ret = TRUE;
 
        text = gtk_editable_get_text (GTK_EDITABLE (self->leap_username_entry));
-       if (!text || !strlen (text)) {
+       if (!text || !*text) {
                widget_set_error (self->leap_username_entry);
                g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing leap-username"));
                ret = FALSE;
@@ -79,7 +79,7 @@ validate (NMAWs *ws, GError **error)
 
        if (   secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED
            || secret_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED
-           || (text && strlen (text))) {
+           || (text && *text)) {
                widget_unset_error (self->leap_password_entry);
        } else {
                widget_set_error (self->leap_password_entry);
diff --git a/src/utils/utils.c b/src/utils/utils.c
index cb769fab..b776e15e 100644
--- a/src/utils/utils.c
+++ b/src/utils/utils.c
@@ -333,7 +333,7 @@ utils_tree_model_get_int64 (GtkTreeModel *model,
        gtk_tree_model_get (model, iter, column, &item, -1);
        if (out_raw)
                *out_raw = item;
-       if (!item || !strlen (item)) {
+       if (!item || !*item) {
                if (!out_raw)
                        g_free (item);
                return fail_if_missing ? FALSE : TRUE;
@@ -373,7 +373,7 @@ utils_tree_model_get_address (GtkTreeModel *model,
        gtk_tree_model_get (model, iter, column, &item, -1);
        if (out_raw)
                *out_raw = item;
-       if (!item || !strlen (item)) {
+       if (!item || !*item) {
                if (!out_raw)
                        g_free (item);
                return fail_if_missing ? FALSE : TRUE;
@@ -412,7 +412,7 @@ utils_tree_model_get_ip4_prefix (GtkTreeModel *model,
        gtk_tree_model_get (model, iter, column, &item, -1);
        if (out_raw)
                *out_raw = item;
-       if (!item || !strlen (item)) {
+       if (!item || !*item) {
                if (!out_raw)
                        g_free (item);
                return fail_if_missing ? FALSE : TRUE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]