Fixed crash when interactions have no instances
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 22 Jul 2011 17:35:43 +0000 (19:35 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 26 Jul 2011 10:36:39 +0000 (12:36 +0200)
src/math/categoricals.c

index 6e39ff2682c45b0bb7c638189d9fe6042711b8a8..67ca1e9addc278f2bda5d0ee50a8a957ccfdfa9c 100644 (file)
@@ -486,6 +486,10 @@ categoricals_done (const struct categoricals *cat_)
       sort (iap->reverse_interaction_value_map, x, sizeof (*iap->reverse_interaction_value_map),
            compare_interaction_value_3way, iap);
 
+      /* Fill the remaining values with null */
+      for (ii = x ; ii < iap->n_cats; ++ii)
+       iap->reverse_interaction_value_map[ii] = NULL;
+
       /* Populate the reverse variable maps. */
       for (ii = 0; ii < iap->df; ++ii)
        cat->reverse_variable_map_short[idx_short++] = i;
@@ -538,6 +542,10 @@ categoricals_get_case_by_subscript (const struct categoricals *cat, int subscrip
   int vindex = reverse_variable_lookup_short (cat, subscript);
   const struct interact_params *vp = &cat->iap[vindex];
   const struct interaction_value *vn = vp->reverse_interaction_value_map [subscript - vp->base_subscript_short];
+
+  if ( vn == NULL)
+    return NULL;
+
   return vn->ccase;
 }
 
@@ -559,6 +567,9 @@ categoricals_get_sum_by_subscript (const struct categoricals *cat, int subscript
 
   const struct interaction_value *iv = vp->reverse_interaction_value_map [subscript - vp->base_subscript_short];
 
+  if (iv == NULL)
+    return 0;
+
   return iv->cc;
 }
 
@@ -572,6 +583,9 @@ categoricals_get_binary_by_subscript (const struct categoricals *cat, int subscr
 
   const struct ccase *c2 =  categoricals_get_case_by_subscript (cat, subscript);
 
+  if ( c2 == NULL)
+    return 0;
+
   return interaction_case_equal (iact, c, c2);
 }