val_labs_equal: Accept null pointers
authorJohn Darrington <john@darrington.wattle.id.au>
Tue, 24 Apr 2012 19:14:17 +0000 (21:14 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 24 Apr 2012 19:14:17 +0000 (21:14 +0200)
Instead of checking for NULL before calling val_labs_equal, put the onus
on the function itself to deal with null pointers and behave appropriately.

src/data/value-labels.c
src/ui/gui/psppire-value-entry.c

index 0b2ae3f6323575dc9711c1de1f8b88f4e34d0df4..c405961f29d69b29a24b767b0095c5029932425d 100644 (file)
@@ -362,7 +362,13 @@ val_labs_equal (const struct val_labs *a, const struct val_labs *b)
 {
   const struct val_lab *label;
 
-  if (val_labs_count (a) != val_labs_count (b) || a->width != b->width)
+  if (val_labs_count (a) != val_labs_count (b))
+    return false;
+  
+  if (a == NULL || b == NULL)
+    return true;
+
+  if (a->width != b->width)
     return false;
 
   HMAP_FOR_EACH (label, struct val_lab, node, &a->labels)
index 4cc8be9871acb1f9c90e151626e407709e2f8101..85dbaa093cb31134a50ca04c50a12622290bdaca 100644 (file)
@@ -319,9 +319,7 @@ void
 psppire_value_entry_set_value_labels (PsppireValueEntry *obj,
                                       const struct val_labs *val_labs)
 {
-  if (val_labs != NULL
-      ? obj->val_labs == NULL || !val_labs_equal (obj->val_labs, val_labs)
-      : obj->val_labs != NULL)
+  if (!val_labs_equal (obj->val_labs, val_labs))
     {
       obj->cur_value = NULL;