[virt-tools-list] [osinfo PATCH 1/3] Handle empty/NULL strings in is_str_empty

Christophe Fergeau cfergeau at redhat.com
Thu Dec 1 09:25:48 UTC 2011


---
 osinfo/osinfo_media.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index 0c54c21..f9769cf 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -514,6 +514,9 @@ static gboolean is_str_empty(const gchar *str) {
     guint8 i;
     gboolean ret = TRUE;
 
+    if ((str == NULL) || (*str == 0))
+        return TRUE;
+
     for (i = 0; i < strlen (str); i++)
         if (!g_ascii_isspace (str[i])) {
            ret = FALSE;
@@ -571,15 +574,15 @@ static void on_svd_read (GObject *source,
                             OSINFO_MEDIA_PROP_URL,
                             uri);
     g_free(uri);
-    if (data->pvd.volume[0] != 0 && !is_str_empty (data->pvd.volume))
+    if (!is_str_empty (data->pvd.volume))
         osinfo_entity_set_param(OSINFO_ENTITY(ret),
                                 OSINFO_MEDIA_PROP_VOLUME_ID,
                                 data->pvd.volume);
-    if (data->pvd.system[0] != 0 && !is_str_empty (data->pvd.system))
+    if (!is_str_empty (data->pvd.system))
         osinfo_entity_set_param(OSINFO_ENTITY(ret),
                                 OSINFO_MEDIA_PROP_SYSTEM_ID,
                                 data->pvd.system);
-    if (data->pvd.publisher[0] != 0 && !is_str_empty (data->pvd.publisher))
+    if (!is_str_empty (data->pvd.publisher))
         osinfo_entity_set_param(OSINFO_ENTITY(ret),
                                 OSINFO_MEDIA_PROP_PUBLISHER_ID,
                                 data->pvd.publisher);
-- 
1.7.7.3




More information about the virt-tools-list mailing list