Merge commit 'origin/stable'
[pspp-builds.git] / src / math / coefficient.c
index 4f987612ff07d727e60d750b3395d19a3a3e0ac2..f78895f8214e4b70b89668477ac1dfe1abc98fe2 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2005 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -153,20 +153,28 @@ pspp_coeff_get_var (struct pspp_coeff *coef, int i)
   categorical, and has more than one coefficient, use the VAL to find
   its coefficient.
  */
-const struct pspp_coeff *
+struct pspp_coeff *
 pspp_coeff_var_to_coeff (const struct variable *v, struct pspp_coeff **coefs, 
                         size_t n_coef, const union value *val)
 {
   size_t i = 0;
   size_t j = 0;
   size_t v_idx;
+
   struct pspp_coeff *result = NULL;
 
   if (v != NULL)
     {
       v_idx = var_get_dict_index (v);
-      while (i < n_coef && var_get_dict_index (coefs[i]->v_info->v) != v_idx)
+      while (i < n_coef)
        {
+         if (coefs[i]->v_info != NULL)
+           {
+             if (var_get_dict_index (coefs[i]->v_info->v) == v_idx)
+               {
+                 break;
+               }
+           }
          i++;
        }
       result = coefs[i];
@@ -177,9 +185,12 @@ pspp_coeff_var_to_coeff (const struct variable *v, struct pspp_coeff **coefs,
           */
          if (val != NULL)
            {
+              int width = var_get_width (v);
+
              j = i;
-             while (j < n_coef && compare_values (pspp_coeff_get_value (coefs[j], v),
-                                                  val, var_get_width (v)) != 0)
+             while (j < n_coef
+                     && value_compare_3way (pspp_coeff_get_value (coefs[j], v),
+                                            val, width) != 0)
                {
                  j++;
                }