From: Ralph Corderoy Date: Tue, 12 Sep 2017 14:02:41 +0000 (+0100) Subject: Hoick FENDNULL(key) out of the search loop. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/459c5e3d66287e314dff8543df32c6c14a8464c6?ds=inline;hp=b080f5bec1263d354ca4943e2bc9670cb1e9cfa7 Hoick FENDNULL(key) out of the search loop. `key' is a loop-invariant so can be tested for NULL once before the loop. In one case, this also avoid passing NULL to printf(3) for "%s", and means getcpy()s can be replaced with mh_xstrdup()s. --- diff --git a/sbr/context_del.c b/sbr/context_del.c index 59e3be70..592af0ca 100644 --- a/sbr/context_del.c +++ b/sbr/context_del.c @@ -18,8 +18,9 @@ context_del (char *key) { struct node *np, *pp; + key = FENDNULL(key); for (np = m_defs, pp = NULL; np; pp = np, np = np->n_next) { - if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(key))) { + if (!strcasecmp(FENDNULL(np->n_name), key)) { if (!np->n_context) inform("bug: context_del(key=\"%s\"), continuing...", np->n_name); if (pp) diff --git a/sbr/context_find.c b/sbr/context_find.c index afeff37e..c6ae2d8c 100644 --- a/sbr/context_find.c +++ b/sbr/context_find.c @@ -13,8 +13,9 @@ context_find (const char *str) { struct node *np; + str = FENDNULL(str); for (np = m_defs; np; np = np->n_next) - if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(str))) + if (!strcasecmp(FENDNULL(np->n_name), str)) return (np->n_field); return NULL; diff --git a/sbr/context_replace.c b/sbr/context_replace.c index 0fdd7b4e..154f3f6b 100644 --- a/sbr/context_replace.c +++ b/sbr/context_replace.c @@ -14,13 +14,15 @@ context_replace (char *key, char *value) { struct node *np; + key = FENDNULL(key); + /* * If list is empty, allocate head of profile/context list. */ if (!m_defs) { NEW(np); m_defs = np; - np->n_name = getcpy (key); + np->n_name = mh_xstrdup(key); np->n_field = getcpy (value); np->n_context = 1; np->n_next = NULL; @@ -33,7 +35,7 @@ context_replace (char *key, char *value) * this key, and replace its value if found. */ for (np = m_defs;; np = np->n_next) { - if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(key))) { + if (!strcasecmp(FENDNULL(np->n_name), key)) { if (strcmp (value, np->n_field)) { if (!np->n_context) inform("bug: context_replace(key=\"%s\",value=\"%s\"), continuing...", key, value); @@ -52,7 +54,7 @@ context_replace (char *key, char *value) */ NEW(np->n_next); np = np->n_next; - np->n_name = getcpy (key); + np->n_name = mh_xstrdup(key); np->n_field = getcpy (value); np->n_context = 1; np->n_next = NULL; diff --git a/uip/post.c b/uip/post.c index 69fe6b86..7cbf9dc9 100644 --- a/uip/post.c +++ b/uip/post.c @@ -1221,8 +1221,9 @@ get_header (char *header, struct headers *table) { struct headers *h; + header = FENDNULL(header); for (h = table; h->value; h++) - if (!strcasecmp (FENDNULL(header), FENDNULL(h->value))) + if (!strcasecmp(FENDNULL(h->value), header)) return (h - table); return NOTOK;