From 1c43a7ff440d6d119c355df6bcf81acfcf99b1c8 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 16 Mar 2012 14:43:06 +0100 Subject: [PATCH] Categoricals: Dont crash when getting non-existant user data --- src/math/categoricals.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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; } -- 2.30.2