From: Jason Stover Date: Sat, 1 Mar 2008 20:53:00 +0000 (+0000) Subject: added checks for pointers to coefficient X-Git-Tag: v0.6.0~83 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7db1398e16e52bd5da6eb828d4e28fe5b5c2fdf0;p=pspp-builds.git added checks for pointers to coefficient --- diff --git a/src/math/ChangeLog b/src/math/ChangeLog index 2c0df305..48b30627 100644 --- a/src/math/ChangeLog +++ b/src/math/ChangeLog @@ -1,3 +1,12 @@ +2008-03-01 Jason Stover + + * coefficient.c (pspp_coeff_init): Ensure first arg is not a null + pointer. + + * coefficient.c (pspp_linreg_get_coeff): Make sure we don't return + a result beyond the last coefficient, or start with a coefficient + beyond the last one if there is only one. + 2007-06-06 Ben Pfaff Adapt case sources, sinks, and clients of procedure code to the diff --git a/src/math/coefficient.c b/src/math/coefficient.c index 44b7c0d3..1868bda4 100644 --- a/src/math/coefficient.c +++ b/src/math/coefficient.c @@ -55,6 +55,7 @@ pspp_coeff_init (struct pspp_coeff ** c, const struct design_matrix *X) size_t i; int n_vals = 1; + assert (c != NULL); for (i = 0; i < X->m->size2; i++) { c[i] = xmalloc (sizeof (*c[i])); @@ -182,7 +183,7 @@ const struct pspp_coeff * pspp_linreg_get_coeff (const pspp_linreg_cache * c, const struct variable *v, const union value *val) { - int i = 1; + int i; struct pspp_coeff *result = NULL; const struct variable *tmp = NULL; @@ -194,7 +195,10 @@ pspp_linreg_get_coeff (const pspp_linreg_cache * c, { return NULL; } - + /* + C->N_COEFFS == 1 means regression through the origin. + */ + i = (c->n_coeffs > 1) ? 1 : 0; result = c->coeff[i]; tmp = pspp_coeff_get_var (result, 0); while (tmp != v && i < c->n_coeffs) @@ -203,7 +207,7 @@ pspp_linreg_get_coeff (const pspp_linreg_cache * c, tmp = pspp_coeff_get_var (result, 0); i++; } - if (i > c->n_coeffs) + if (i >= c->n_coeffs) { return NULL; }