]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Improve argument names of xmemmem
authorBrad King <brad.king@kitware.com>
Thu, 22 Oct 2015 14:02:14 +0000 (10:02 -0400)
committerBrad King <brad.king@kitware.com>
Mon, 26 Oct 2015 13:21:59 +0000 (09:21 -0400)
AIX system headers define the symbol 'hz' as a preprocessor macro.
Rename the arguments to avoid this name and be more readable.

Suggested-by: Joerg Sonnenberger
libarchive/archive_read_support_format_warc.c

index 6bd15f6b7ab9850c58f39b816108d2ad8199caf1..46a59ea14ba8ee370ca5004de7552e58b0869c9e 100644 (file)
@@ -418,10 +418,11 @@ deconst(const void *c)
 }
 
 static char*
-xmemmem(const char *hay, const size_t hz, const char *ndl, const size_t nz)
+xmemmem(const char *hay, const size_t haysize,
+       const char *needle, const size_t needlesize)
 {
-       const char *const eoh = hay + hz;
-       const char *const eon = ndl + nz;
+       const char *const eoh = hay + haysize;
+       const char *const eon = needle + needlesize;
        const char *hp;
        const char *np;
        const char *cand;
@@ -433,9 +434,9 @@ xmemmem(const char *hay, const size_t hz, const char *ndl, const size_t nz)
          * a 0-sized needle is defined to be found anywhere in haystack
          * then run strchr() to find a candidate in HAYSTACK (i.e. a portion
          * that happens to begin with *NEEDLE) */
-       if (nz == 0UL) {
+       if (needlesize == 0UL) {
                return deconst(hay);
-       } else if ((hay = memchr(hay, *ndl, hz)) == NULL) {
+       } else if ((hay = memchr(hay, *needle, haysize)) == NULL) {
                /* trivial */
                return NULL;
        }
@@ -444,11 +445,11 @@ xmemmem(const char *hay, const size_t hz, const char *ndl, const size_t nz)
         * guaranteed to be at least one character long.  Now computes the sum
         * of characters values of needle together with the sum of the first
         * needle_len characters of haystack. */
-       for (hp = hay + 1U, np = ndl + 1U, hsum = *hay, nsum = *hay, eqp = 1U;
+       for (hp = hay + 1U, np = needle + 1U, hsum = *hay, nsum = *hay, eqp = 1U;
             hp < eoh && np < eon;
             hsum ^= *hp, nsum ^= *np, eqp &= *hp == *np, hp++, np++);
 
-       /* HP now references the (NZ + 1)-th character. */
+       /* HP now references the (NEEDLESIZE + 1)-th character. */
        if (np < eon) {
                /* haystack is smaller than needle, :O */
                return NULL;
@@ -464,10 +465,10 @@ xmemmem(const char *hay, const size_t hz, const char *ndl, const size_t nz)
                hsum ^= *hp;
 
                /* Since the sum of the characters is already known to be
-                * equal at that point, it is enough to check just NZ - 1
+                * equal at that point, it is enough to check just NEEDLESIZE - 1
                 * characters for equality,
                 * also CAND is by design < HP, so no need for range checks */
-               if (hsum == nsum && memcmp(cand, ndl, nz - 1U) == 0) {
+               if (hsum == nsum && memcmp(cand, needle, needlesize - 1U) == 0) {
                        return deconst(cand);
                }
        }