From: Adam Dickmeiss Date: Wed, 14 Oct 2009 14:27:48 +0000 (+0200) Subject: Fix nasty bug of overrides not working X-Git-Tag: v1.2.3~22 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=85a3ecf154edbf4a0d7ca8b8d4e72c2e94d00a6d;p=pazpar2-moved-to-github.git Fix nasty bug of overrides not working --- diff --git a/src/settings.c b/src/settings.c index 155dac7..72a47d0 100644 --- a/src/settings.c +++ b/src/settings.c @@ -336,7 +336,7 @@ static void update_database(void *context, struct database *db) context)->set; struct conf_service *service = ((struct update_database_context *) context)->service; - struct setting *s, **sp; + struct setting **sp; int offset; // Is this the right database? @@ -348,24 +348,34 @@ static void update_database(void *context, struct database *db) // First we determine if this setting is overriding any existing settings // with the same name. - for (s = db->settings[offset], sp = &db->settings[offset]; s; - sp = &s->next, s = s->next) - if (!strcmp(s->name, set->name)) + assert(offset < db->num_settings); + for (sp = &db->settings[offset]; *sp; ) + if (!strcmp((*sp)->name, set->name)) { - if (s->precedence < set->precedence) + if ((*sp)->precedence < set->precedence) + { // We discard the value (nmem keeps track of the space) *sp = (*sp)->next; // unlink value from existing setting - else if (s->precedence > set->precedence) + } + else if ((*sp)->precedence > set->precedence) + { // Db contains a higher-priority setting. Abort search break; - if (zurl_wildcard(s->target) > zurl_wildcard(set->target)) + } + else if (zurl_wildcard((*sp)->target) > zurl_wildcard(set->target)) + { // target-specific value trumps wildcard. Delete. *sp = (*sp)->next; // unlink..... - else if (!zurl_wildcard(s->target)) + } + else if (!zurl_wildcard((*sp)->target)) // Db already contains higher-priority setting. Abort search break; + else + sp = &(*sp)->next; } - if (!s) // s will be null when there are no higher-priority settings -- we add one + else + sp = &(*sp)->next; + if (!*sp) // is null when there are no higher-priority settings, so we add one { struct setting *new = nmem_malloc(service->nmem, sizeof(*new));