From fb444ac16dca6eade462a45ccd9fc92e5dfa0069 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 2 Nov 2012 15:31:45 +0100 Subject: [PATCH] Categoricals: Accept null pointer as subject. Previously, certain functions would crash, or behave badly if their argument was NULL. This change makes them do nothing, or return default values, as appropriate. This saves callers having to always test for NULL. --- src/math/categoricals.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/math/categoricals.c b/src/math/categoricals.c index 2a0d4f85ba..fdd552fed5 100644 --- a/src/math/categoricals.c +++ b/src/math/categoricals.c @@ -358,6 +358,10 @@ categoricals_update (struct categoricals *cat, const struct ccase *c) { int i; struct variable_node *vn = NULL; + + if (NULL == cat) + return; + const double weight = cat->wv ? case_data (c, cat->wv)->f : 1.0; assert (NULL == cat->reverse_variable_map_short); @@ -453,6 +457,9 @@ categoricals_n_total (const struct categoricals *cat) size_t categoricals_df_total (const struct categoricals *cat) { + if (NULL == cat) + return 0; + return cat->df_sum; } @@ -479,6 +486,10 @@ categoricals_done (const struct categoricals *cat_) int i; int idx_short = 0; int idx_long = 0; + + if (NULL == cat) + return; + cat->df_sum = 0; cat->n_cats_total = 0; -- 2.30.2