From: John Darrington Date: Fri, 16 Mar 2012 13:43:06 +0000 (+0100) Subject: Categoricals: Dont crash when getting non-existant user data X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c43a7ff440d6d119c355df6bcf81acfcf99b1c8;p=pspp Categoricals: Dont crash when getting non-existant user data --- diff --git a/src/math/categoricals.c b/src/math/categoricals.c index 5aeb7e213c..5b5e2539ad 100644 --- a/src/math/categoricals.c +++ b/src/math/categoricals.c @@ -697,8 +697,14 @@ categoricals_get_n_variables (const struct categoricals *cat) const struct ccase * categoricals_get_case_by_category_real (const struct categoricals *cat, int iact, int n) { + const struct interaction_value *vn; + const struct interact_params *vp = &cat->iap[iact]; - const struct interaction_value *vn = vp->reverse_interaction_value_map [n]; + + if ( n >= hmap_count (&vp->ivmap)) + return NULL; + + vn = vp->reverse_interaction_value_map [n]; return vn->ccase; } @@ -708,7 +714,12 @@ void * categoricals_get_user_data_by_category_real (const struct categoricals *cat, int iact, int n) { const struct interact_params *vp = &cat->iap[iact]; - const struct interaction_value *iv = vp->reverse_interaction_value_map [n]; + const struct interaction_value *iv ; + + if ( n >= hmap_count (&vp->ivmap)) + return NULL; + + iv = vp->reverse_interaction_value_map [n]; return iv->user_data; }