[master] a98c14896 Align code with with zlib 1.2.11.

Poul-Henning Kamp phk at FreeBSD.org
Thu Feb 25 09:26:08 UTC 2021


commit a98c1489640c8098b8e6e80ebcd9831c0a7f087b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Feb 25 09:24:22 2021 +0000

    Align code with with zlib 1.2.11.
    
    FreeBSD's code is undergoing some compatibility adaptations
    so we go directly to the source from here.
    
    PS: Please keep cochinelle out of libvgz.

diff --git a/lib/libvgz/adler32.c b/lib/libvgz/adler32.c
index 436252be4..5f5e0decd 100644
--- a/lib/libvgz/adler32.c
+++ b/lib/libvgz/adler32.c
@@ -137,7 +137,7 @@ uLong ZEXPORT adler32(adler, buf, len)
     const Bytef *buf;
     uInt len;
 {
-    return (adler32_z(adler, buf, len));
+    return adler32_z(adler, buf, len);
 }
 
 /* ========================================================================= */
@@ -152,7 +152,7 @@ local uLong adler32_combine_(adler1, adler2, len2)
 
     /* for negative len, return invalid adler32 as a clue for debugging */
     if (len2 < 0)
-        return (0xffffffffUL);
+        return 0xffffffffUL;
 
     /* the derivation of this formula is left as an exercise for the reader */
     MOD63(len2);                /* assumes len2 >= 0 */
@@ -166,7 +166,7 @@ local uLong adler32_combine_(adler1, adler2, len2)
     if (sum1 >= BASE) sum1 -= BASE;
     if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
     if (sum2 >= BASE) sum2 -= BASE;
-    return (sum1 | (sum2 << 16));
+    return sum1 | (sum2 << 16);
 }
 
 /* ========================================================================= */
@@ -175,7 +175,7 @@ uLong ZEXPORT adler32_combine(adler1, adler2, len2)
     uLong adler2;
     z_off_t len2;
 {
-    return (adler32_combine_(adler1, adler2, len2));
+    return adler32_combine_(adler1, adler2, len2);
 }
 
 uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
@@ -183,7 +183,7 @@ uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
     uLong adler2;
     z_off64_t len2;
 {
-    return (adler32_combine_(adler1, adler2, len2));
+    return adler32_combine_(adler1, adler2, len2);
 }
 #else
 uLong ZEXPORT adler32(adler, buf, len)
diff --git a/lib/libvgz/crc32.c b/lib/libvgz/crc32.c
index 9ec56fc34..9580440c0 100644
--- a/lib/libvgz/crc32.c
+++ b/lib/libvgz/crc32.c
@@ -191,7 +191,7 @@ const z_crc_t FAR * ZEXPORT get_crc_table()
     if (crc_table_empty)
         make_crc_table();
 #endif /* DYNAMIC_CRC_TABLE */
-    return ((const z_crc_t FAR *)crc_table);
+    return (const z_crc_t FAR *)crc_table;
 }
 
 /* ========================================================================= */
@@ -204,7 +204,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
     const unsigned char FAR *buf;
     z_size_t len;
 {
-    if (buf == Z_NULL) return (0UL);
+    if (buf == Z_NULL) return 0UL;
 
 #ifdef DYNAMIC_CRC_TABLE
     if (crc_table_empty)
@@ -217,9 +217,9 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
 
         endian = 1;
         if (*((unsigned char *)(&endian)))
-            return (crc32_little(crc, buf, len));
+            return crc32_little(crc, buf, len);
         else
-            return (crc32_big(crc, buf, len));
+            return crc32_big(crc, buf, len);
     }
 #endif /* BYFOUR */
     crc = crc ^ 0xffffffffUL;
@@ -230,7 +230,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
     if (len) do {
         DO1;
     } while (--len);
-    return (crc ^ 0xffffffffUL);
+    return crc ^ 0xffffffffUL;
 }
 
 /* ========================================================================= */
@@ -239,7 +239,7 @@ unsigned long ZEXPORT crc32(crc, buf, len)
     const unsigned char FAR *buf;
     uInt len;
 {
-    return (crc32_z(crc, buf, len));
+    return crc32_z(crc, buf, len);
 }
 
 #ifdef BYFOUR
@@ -381,7 +381,7 @@ local uLong crc32_combine_(crc1, crc2, len2)
 
     /* degenerate case (also disallow negative lengths) */
     if (len2 <= 0)
-        return (crc1);
+        return crc1;
 
     /* put operator for one zero bit in odd */
     odd[0] = 0xedb88320UL;          /* CRC-32 polynomial */
@@ -421,7 +421,7 @@ local uLong crc32_combine_(crc1, crc2, len2)
 
     /* return combined crc */
     crc1 ^= crc2;
-    return (crc1);
+    return crc1;
 }
 
 /* ========================================================================= */
@@ -430,7 +430,7 @@ uLong ZEXPORT crc32_combine(crc1, crc2, len2)
     uLong crc2;
     z_off_t len2;
 {
-    return (crc32_combine_(crc1, crc2, len2));
+    return crc32_combine_(crc1, crc2, len2);
 }
 
 uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
@@ -438,5 +438,5 @@ uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
     uLong crc2;
     z_off64_t len2;
 {
-    return (crc32_combine_(crc1, crc2, len2));
+    return crc32_combine_(crc1, crc2, len2);
 }
diff --git a/lib/libvgz/deflate.c b/lib/libvgz/deflate.c
index 2a2544783..e4493c125 100644
--- a/lib/libvgz/deflate.c
+++ b/lib/libvgz/deflate.c
@@ -511,7 +511,7 @@ int ZEXPORT deflateResetKeep (strm)
         s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
 #endif
         adler32(0L, Z_NULL, 0);
-    s->last_flush = -2;
+    s->last_flush = Z_NO_FLUSH;
 
     _tr_init(s);
 
@@ -606,12 +606,12 @@ int ZEXPORT deflateParams(strm, level, strategy)
     func = configuration_table[s->level].func;
 
     if ((strategy != s->strategy || func != configuration_table[level].func) &&
-        s->last_flush != -2) {
+        s->high_water) {
         /* Flush the last buffer: */
         int err = deflate(strm, Z_BLOCK);
         if (err == Z_STREAM_ERROR)
             return err;
-        if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead)
+        if (strm->avail_out == 0)
             return Z_BUF_ERROR;
     }
     if (s->level != level) {
diff --git a/lib/libvgz/inflate.c b/lib/libvgz/inflate.c
index 93730905a..ca7b6086d 100644
--- a/lib/libvgz/inflate.c
+++ b/lib/libvgz/inflate.c
@@ -246,7 +246,7 @@ z_streamp strm;
 const char *version;
 int stream_size;
 {
-    return (inflateInit2_(strm, DEF_WBITS, version, stream_size));
+    return inflateInit2_(strm, DEF_WBITS, version, stream_size);
 }
 
 int ZEXPORT inflatePrime(strm, bits, value)
diff --git a/lib/libvgz/trees.c b/lib/libvgz/trees.c
index a08b09da3..a11cd0d48 100644
--- a/lib/libvgz/trees.c
+++ b/lib/libvgz/trees.c
@@ -823,7 +823,7 @@ local int build_bl_tree(s)
     Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
             s->opt_len, s->static_len));
 
-    return (max_blindex);
+    return max_blindex;
 }
 
 /* ===========================================================================
@@ -1062,10 +1062,10 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
         Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
                s->last_lit, in_length, out_length,
                100L - out_length*100L/in_length));
-        if (s->matches < s->last_lit/2 && out_length < in_length/2) return (1);
+        if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
     }
 #endif
-    return (s->last_lit == s->lit_bufsize - 1);
+    return (s->last_lit == s->lit_bufsize-1);
     /* We avoid equality with lit_bufsize because of wraparound at 64K
      * on 16 bit machines and because stored blocks are restricted to
      * 64K-1 bytes.
@@ -1148,20 +1148,20 @@ local int detect_data_type(s)
     /* Check for non-textual ("black-listed") bytes. */
     for (n = 0; n <= 31; n++, black_mask >>= 1)
         if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0))
-            return (Z_BINARY);
+            return Z_BINARY;
 
     /* Check for textual ("white-listed") bytes. */
     if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
             || s->dyn_ltree[13].Freq != 0)
-        return (Z_TEXT);
+        return Z_TEXT;
     for (n = 32; n < LITERALS; n++)
         if (s->dyn_ltree[n].Freq != 0)
-            return (Z_TEXT);
+            return Z_TEXT;
 
     /* There are no "black-listed" or "white-listed" bytes:
      * this stream either is empty or has tolerated ("gray-listed") bytes only.
      */
-    return (Z_BINARY);
+    return Z_BINARY;
 }
 
 /* ===========================================================================
diff --git a/lib/libvgz/vgz.h b/lib/libvgz/vgz.h
index 1bb81009d..342a0fba5 100644
--- a/lib/libvgz/vgz.h
+++ b/lib/libvgz/vgz.h
@@ -717,12 +717,11 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
    used to switch between compression and straight copy of the input data, or
    to switch to a different kind of input data requiring a different strategy.
    If the compression approach (which is a function of the level) or the
-   strategy is changed, and if there have been any deflate() calls since the
-   state was initialized or reset, then the input available so far is
-   compressed with the old level and strategy using deflate(strm, Z_BLOCK).
-   There are three approaches for the compression levels 0, 1..3, and 4..9
-   respectively.  The new level and strategy will take effect at the next call
-   of deflate().
+   strategy is changed, and if any input has been consumed in a previous
+   deflate() call, then the input available so far is compressed with the old
+   level and strategy using deflate(strm, Z_BLOCK).  There are three approaches
+   for the compression levels 0, 1..3, and 4..9 respectively.  The new level
+   and strategy will take effect at the next call of deflate().
 
      If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
    not have enough output space to complete, then the parameter change will not
diff --git a/lib/libvgz/zconf.h b/lib/libvgz/zconf.h
index 1afeed62a..21f3eada7 100644
--- a/lib/libvgz/zconf.h
+++ b/lib/libvgz/zconf.h
@@ -3,7 +3,7 @@
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-/* @(#) $FreeBSD: head/contrib/zlib/zconf.h 311285 2017-01-04 16:09:08Z delphij $ */
+/* @(#) $Id$ */
 
 #ifndef ZCONF_H
 #define ZCONF_H
@@ -431,7 +431,7 @@ typedef uLong FAR uLongf;
    typedef unsigned long z_crc_t;
 #endif
 
-#if 0    /* was set to #if 0 by ./configure */
+#ifdef HAVE_UNISTD_H    /* may be set to #if 1 by ./configure */
 #  define Z_HAVE_UNISTD_H
 #endif
 
@@ -500,15 +500,8 @@ typedef uLong FAR uLongf;
 #  define SEEK_END        2       /* Set file pointer to EOF plus "offset" */
 #endif
 
-/*
- * This is hard-configured for FreeBSD.
- */
-#define	z_off_t	off_t
-#ifndef _FILE_OFFSET_BITS
-#define _FILE_OFFSET_BITS 64
-#endif
-
 #ifndef z_off_t
+# error "z_off_t missing"
 #  define z_off_t long
 #endif
 
diff --git a/lib/libvgz/zutil.c b/lib/libvgz/zutil.c
index e65fd04b8..5b21eceda 100644
--- a/lib/libvgz/zutil.c
+++ b/lib/libvgz/zutil.c
@@ -27,7 +27,7 @@ z_const char * const z_errmsg[10] = {
 
 const char * ZEXPORT zlibVersion()
 {
-    return (ZLIB_VERSION);
+    return ZLIB_VERSION;
 }
 
 uLong ZEXPORT zlibCompileFlags()
@@ -110,7 +110,7 @@ uLong ZEXPORT zlibCompileFlags()
 #    endif
 #  endif
 #endif
-    return (flags);
+    return flags;
 }
 
 #ifdef ZLIB_DEBUG
@@ -134,7 +134,7 @@ void ZLIB_INTERNAL z_error (m)
 const char * ZEXPORT zError(err)
     int err;
 {
-    return (ERR_MSG(err));
+    return ERR_MSG(err);
 }
 
 #if defined(_WIN32_WCE)
@@ -166,9 +166,9 @@ int ZLIB_INTERNAL zmemcmp(s1, s2, len)
     uInt j;
 
     for (j = 0; j < len; j++) {
-        if (s1[j] != s2[j]) return (2 * (s1[j] > s2[j]) - 1);
+        if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
     }
-    return (0);
+    return 0;
 }
 
 void ZLIB_INTERNAL zmemzero(dest, len)
@@ -229,18 +229,18 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
      */
     if (bsize < 65520L) {
         buf = farmalloc(bsize);
-        if (*(ush*)&buf != 0) return (buf);
+        if (*(ush*)&buf != 0) return buf;
     } else {
         buf = farmalloc(bsize + 16L);
     }
-    if (buf == NULL || next_ptr >= MAX_PTR) return (NULL);
+    if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
     table[next_ptr].org_ptr = buf;
 
     /* Normalize the pointer to seg:0 */
     *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
     *(ush*)&buf = 0;
     table[next_ptr++].new_ptr = buf;
-    return (buf);
+    return buf;
 }
 
 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
@@ -283,7 +283,7 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
 voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
 {
     (void)opaque;
-    return (_halloc((long)items, size));
+    return _halloc((long)items, size);
 }
 
 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)


More information about the varnish-commit mailing list