From: Zdenek Dohnal Date: Tue, 7 Jan 2025 17:49:53 +0000 (+0100) Subject: search.c: newer free() accepts NULL X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ef9f9ba9a2f37bae199ef98ade43498cad79318;p=thirdparty%2Fcups.git search.c: newer free() accepts NULL --- diff --git a/cgi-bin/search.c b/cgi-bin/search.c index 823d056525..136d12d569 100644 --- a/cgi-bin/search.c +++ b/cgi-bin/search.c @@ -105,14 +105,13 @@ cgiCompileSearch(const char *query) /* I - Query string */ if (!*qend) { /* - * No closing quote, error out! + * No closing quote, error out! */ free(s); free(re); - if (lword) - free(lword); + free(lword); return (NULL); } @@ -140,7 +139,7 @@ cgiCompileSearch(const char *query) /* I - Query string */ */ if (sptr > s) - prefix = ".*"; + prefix = ".*"; qptr = qend; } @@ -151,7 +150,7 @@ cgiCompileSearch(const char *query) /* I - Query string */ */ if (sptr > s) - prefix = ".*|.*"; + prefix = ".*|.*"; qptr = qend; } @@ -164,7 +163,7 @@ cgiCompileSearch(const char *query) /* I - Query string */ wlen = (size_t)(sptr - s) + 2 * 4 * wlen + 2 * strlen(prefix) + 11; if (lword) - wlen += strlen(lword); + wlen += strlen(lword); if (wlen > slen) { @@ -183,8 +182,7 @@ cgiCompileSearch(const char *query) /* I - Query string */ free(s); free(re); - if (lword) - free(lword); + free(lword); return (NULL); } @@ -210,10 +208,10 @@ cgiCompileSearch(const char *query) /* I - Query string */ while (qptr < qend) { /* - * Quote: ^ . [ $ ( ) | * + ? { \ + * Quote: ^ . [ $ ( ) | * + ? { \ */ - if (strchr("^.[$()|*+?{\\", *qptr)) + if (strchr("^.[$()|*+?{\\", *qptr)) *sptr++ = '\\'; *sptr++ = *qptr++; @@ -227,10 +225,10 @@ cgiCompileSearch(const char *query) /* I - Query string */ if (!strcmp(prefix, ".*") && lword) { - char *lword2; /* New "last word" */ + char *lword2; /* New "last word" */ - if ((lword2 = strdup(sword)) == NULL) + if ((lword2 = strdup(sword)) == NULL) { free(lword); free(s); @@ -238,25 +236,24 @@ cgiCompileSearch(const char *query) /* I - Query string */ return (NULL); } - memcpy(sptr, ".*|.*", 6); + memcpy(sptr, ".*|.*", 6); sptr += 5; memcpy(sptr, lword2, strlen(lword2) + 1); sptr += strlen(sptr); - memcpy(sptr, ".*", 3); + memcpy(sptr, ".*", 3); sptr += 2; memcpy(sptr, lword, strlen(lword) + 1); sptr += strlen(sptr); - free(lword); + free(lword); lword = lword2; } else { - if (lword) - free(lword); + free(lword); lword = strdup(sword); } @@ -272,8 +269,7 @@ cgiCompileSearch(const char *query) /* I - Query string */ qptr ++; } - if (lword) - free(lword); + free(lword); if (sptr > s) memcpy(sptr, ".*", 3);