From 62ba4dabf1e240edbe52765d75db7158e446e9a6 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 18 May 2011 14:54:50 +0200 Subject: [PATCH] Facet response: fix null ptr reference This could occur for session_database sdb. Also refactor code inside client_report_facets. --- src/client.c | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/client.c b/src/client.c index dd3b58c..0ea7512 100644 --- a/src/client.c +++ b/src/client.c @@ -425,40 +425,42 @@ static int nativesyntax_to_type(struct session_database *sdb, char *type, */ void client_report_facets(struct client *cl, ZOOM_resultset rs) { - int facet_idx; struct session_database *sdb = client_get_database(cl); ZOOM_facet_field *facets = ZOOM_resultset_facets(rs); - int facet_num; - struct session *se = client_get_session(cl); - struct setting *s; - facet_num = ZOOM_resultset_facets_size(rs); - yaz_log(YLOG_DEBUG, "client_report_facets: %d", facet_num); - for (s = sdb->settings[PZ_FACETMAP]; s; s = s->next) + if (sdb && facets) { - const char *p = strchr(s->name + 3, ':'); - if (p && p[1] && s->value && s->value[0]) + struct session *se = client_get_session(cl); + int facet_num = ZOOM_resultset_facets_size(rs); + struct setting *s; + + for (s = sdb->settings[PZ_FACETMAP]; s; s = s->next) { - p++; /* p now holds logical facet name */ - for (facet_idx = 0; facet_idx < facet_num; facet_idx++) + const char *p = strchr(s->name + 3, ':'); + if (p && p[1] && s->value && s->value[0]) { - const char *native_name = - ZOOM_facet_field_name(facets[facet_idx]); - if (native_name && !strcmp(s->value, native_name)) + int facet_idx; + p++; /* p now holds logical facet name */ + for (facet_idx = 0; facet_idx < facet_num; facet_idx++) { - size_t term_idx; - size_t term_num = - ZOOM_facet_field_term_count(facets[facet_idx]); - for (term_idx = 0; term_idx < term_num; term_idx++ ) + const char *native_name = + ZOOM_facet_field_name(facets[facet_idx]); + if (native_name && !strcmp(s->value, native_name)) { - int freq; - const char *term = - ZOOM_facet_field_get_term(facets[facet_idx], - term_idx, &freq); - if (term) - add_facet(se, p, term, freq); + size_t term_idx; + size_t term_num = + ZOOM_facet_field_term_count(facets[facet_idx]); + for (term_idx = 0; term_idx < term_num; term_idx++ ) + { + int freq; + const char *term = + ZOOM_facet_field_get_term(facets[facet_idx], + term_idx, &freq); + if (term) + add_facet(se, p, term, freq); + } + break; } - break; } } } -- 1.7.10.4