[virt-tools-list] [RFC virt-viewer 08/12] util: Improve empty string handling in virt_viewer_compare_buildid
Christophe Fergeau
cfergeau at redhat.com
Tue Jun 2 14:29:25 UTC 2015
When getting NULL or "" for one of the buildid components, it will be
considered as less than the other component, unless the other component
is also NULL or "". This matches what g_strcmp0 does and what strcmp
does for "" strings.
---
src/virt-viewer-util.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/virt-viewer-util.c b/src/virt-viewer-util.c
index e34336a..14e1de8 100644
--- a/src/virt-viewer-util.c
+++ b/src/virt-viewer-util.c
@@ -439,14 +439,24 @@ spice_hotkey_to_gtk_accelerator(const gchar *key)
return accel;
}
+static gboolean str_is_empty(const gchar *str)
+{
+ return ((str == NULL) || (str[0] == '\0'));
+}
+
static gint
virt_viewer_compare_version(const gchar *s1, const gchar *s2)
{
gint i, retval = 0;
gchar **v1, **v2;
- g_return_val_if_fail(s1 != NULL, G_MAXINT);
- g_return_val_if_fail(s2 != NULL, G_MAXINT);
+ if (str_is_empty(s1) && str_is_empty(s2)) {
+ return 0;
+ } else if (str_is_empty(s1)) {
+ return -1;
+ } else if (str_is_empty(s2)) {
+ return 1;
+ }
v1 = g_strsplit(s1, ".", -1);
v2 = g_strsplit(s2, ".", -1);
--
2.4.2
More information about the virt-tools-list
mailing list