From: John Darrington Date: Fri, 2 Nov 2012 14:31:45 +0000 (+0100) Subject: Categoricals: Accept null pointer as subject. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb444ac16dca6eade462a45ccd9fc92e5dfa0069;p=pspp 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. --- 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;