Skip to content

Commit 49c9f4a

Browse files
authored
Merge pull request #30 from hasufell/bump-bundled-zlib
Update bundled zlib to 1.2.11
2 parents b862431 + a742c04 commit 49c9f4a

19 files changed

+1242
-770
lines changed

cbits/adler32.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
/* adler32.c -- compute the Adler-32 checksum of a data stream
2-
* Copyright (C) 1995-2011 Mark Adler
2+
* Copyright (C) 1995-2011, 2016 Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55

66
/* @(#) $Id$ */
77

88
#include "zutil.h"
99

10-
#define local static
11-
1210
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
1311

14-
#define BASE 65521 /* largest prime smaller than 65536 */
12+
#define BASE 65521U /* largest prime smaller than 65536 */
1513
#define NMAX 5552
1614
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
1715

@@ -62,10 +60,10 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
6260
#endif
6361

6462
/* ========================================================================= */
65-
uLong ZEXPORT adler32(adler, buf, len)
63+
uLong ZEXPORT adler32_z(adler, buf, len)
6664
uLong adler;
6765
const Bytef *buf;
68-
uInt len;
66+
z_size_t len;
6967
{
7068
unsigned long sum2;
7169
unsigned n;
@@ -132,6 +130,15 @@ uLong ZEXPORT adler32(adler, buf, len)
132130
return adler | (sum2 << 16);
133131
}
134132

133+
/* ========================================================================= */
134+
uLong ZEXPORT adler32(adler, buf, len)
135+
uLong adler;
136+
const Bytef *buf;
137+
uInt len;
138+
{
139+
return adler32_z(adler, buf, len);
140+
}
141+
135142
/* ========================================================================= */
136143
local uLong adler32_combine_(adler1, adler2, len2)
137144
uLong adler1;
@@ -156,7 +163,7 @@ local uLong adler32_combine_(adler1, adler2, len2)
156163
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
157164
if (sum1 >= BASE) sum1 -= BASE;
158165
if (sum1 >= BASE) sum1 -= BASE;
159-
if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
166+
if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
160167
if (sum2 >= BASE) sum2 -= BASE;
161168
return sum1 | (sum2 << 16);
162169
}

cbits/compress.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* compress.c -- compress a memory buffer
2-
* Copyright (C) 1995-2005 Jean-loup Gailly.
2+
* Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55

@@ -28,16 +28,11 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
2828
{
2929
z_stream stream;
3030
int err;
31+
const uInt max = (uInt)-1;
32+
uLong left;
3133

32-
stream.next_in = (z_const Bytef *)source;
33-
stream.avail_in = (uInt)sourceLen;
34-
#ifdef MAXSEG_64K
35-
/* Check for source > 64K on 16-bit machine: */
36-
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
37-
#endif
38-
stream.next_out = dest;
39-
stream.avail_out = (uInt)*destLen;
40-
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
34+
left = *destLen;
35+
*destLen = 0;
4136

4237
stream.zalloc = (alloc_func)0;
4338
stream.zfree = (free_func)0;
@@ -46,15 +41,26 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
4641
err = deflateInit(&stream, level);
4742
if (err != Z_OK) return err;
4843

49-
err = deflate(&stream, Z_FINISH);
50-
if (err != Z_STREAM_END) {
51-
deflateEnd(&stream);
52-
return err == Z_OK ? Z_BUF_ERROR : err;
53-
}
54-
*destLen = stream.total_out;
44+
stream.next_out = dest;
45+
stream.avail_out = 0;
46+
stream.next_in = (z_const Bytef *)source;
47+
stream.avail_in = 0;
48+
49+
do {
50+
if (stream.avail_out == 0) {
51+
stream.avail_out = left > (uLong)max ? max : (uInt)left;
52+
left -= stream.avail_out;
53+
}
54+
if (stream.avail_in == 0) {
55+
stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen;
56+
sourceLen -= stream.avail_in;
57+
}
58+
err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
59+
} while (err == Z_OK);
5560

56-
err = deflateEnd(&stream);
57-
return err;
61+
*destLen = stream.total_out;
62+
deflateEnd(&stream);
63+
return err == Z_STREAM_END ? Z_OK : err;
5864
}
5965

6066
/* ===========================================================================

cbits/crc32.c

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* crc32.c -- compute the CRC-32 of a data stream
2-
* Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
2+
* Copyright (C) 1995-2006, 2010, 2011, 2012, 2016 Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*
55
* Thanks to Rodney Brown <[email protected]> for his contribution of faster
@@ -30,17 +30,15 @@
3030

3131
#include "zutil.h" /* for STDC and FAR definitions */
3232

33-
#define local static
34-
3533
/* Definitions for doing the crc four data bytes at a time. */
3634
#if !defined(NOBYFOUR) && defined(Z_U4)
3735
# define BYFOUR
3836
#endif
3937
#ifdef BYFOUR
4038
local unsigned long crc32_little OF((unsigned long,
41-
const unsigned char FAR *, unsigned));
39+
const unsigned char FAR *, z_size_t));
4240
local unsigned long crc32_big OF((unsigned long,
43-
const unsigned char FAR *, unsigned));
41+
const unsigned char FAR *, z_size_t));
4442
# define TBLS 8
4543
#else
4644
# define TBLS 1
@@ -201,10 +199,10 @@ const z_crc_t FAR * ZEXPORT get_crc_table()
201199
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
202200

203201
/* ========================================================================= */
204-
unsigned long ZEXPORT crc32(crc, buf, len)
202+
unsigned long ZEXPORT crc32_z(crc, buf, len)
205203
unsigned long crc;
206204
const unsigned char FAR *buf;
207-
uInt len;
205+
z_size_t len;
208206
{
209207
if (buf == Z_NULL) return 0UL;
210208

@@ -235,8 +233,29 @@ unsigned long ZEXPORT crc32(crc, buf, len)
235233
return crc ^ 0xffffffffUL;
236234
}
237235

236+
/* ========================================================================= */
237+
unsigned long ZEXPORT crc32(crc, buf, len)
238+
unsigned long crc;
239+
const unsigned char FAR *buf;
240+
uInt len;
241+
{
242+
return crc32_z(crc, buf, len);
243+
}
244+
238245
#ifdef BYFOUR
239246

247+
/*
248+
This BYFOUR code accesses the passed unsigned char * buffer with a 32-bit
249+
integer pointer type. This violates the strict aliasing rule, where a
250+
compiler can assume, for optimization purposes, that two pointers to
251+
fundamentally different types won't ever point to the same memory. This can
252+
manifest as a problem only if one of the pointers is written to. This code
253+
only reads from those pointers. So long as this code remains isolated in
254+
this compilation unit, there won't be a problem. For this reason, this code
255+
should not be copied and pasted into a compilation unit in which other code
256+
writes to the buffer that is passed to these routines.
257+
*/
258+
240259
/* ========================================================================= */
241260
#define DOLIT4 c ^= *buf4++; \
242261
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
@@ -247,7 +266,7 @@ unsigned long ZEXPORT crc32(crc, buf, len)
247266
local unsigned long crc32_little(crc, buf, len)
248267
unsigned long crc;
249268
const unsigned char FAR *buf;
250-
unsigned len;
269+
z_size_t len;
251270
{
252271
register z_crc_t c;
253272
register const z_crc_t FAR *buf4;
@@ -278,7 +297,7 @@ local unsigned long crc32_little(crc, buf, len)
278297
}
279298

280299
/* ========================================================================= */
281-
#define DOBIG4 c ^= *++buf4; \
300+
#define DOBIG4 c ^= *buf4++; \
282301
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
283302
crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
284303
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
@@ -287,7 +306,7 @@ local unsigned long crc32_little(crc, buf, len)
287306
local unsigned long crc32_big(crc, buf, len)
288307
unsigned long crc;
289308
const unsigned char FAR *buf;
290-
unsigned len;
309+
z_size_t len;
291310
{
292311
register z_crc_t c;
293312
register const z_crc_t FAR *buf4;
@@ -300,7 +319,6 @@ local unsigned long crc32_big(crc, buf, len)
300319
}
301320

302321
buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
303-
buf4--;
304322
while (len >= 32) {
305323
DOBIG32;
306324
len -= 32;
@@ -309,7 +327,6 @@ local unsigned long crc32_big(crc, buf, len)
309327
DOBIG4;
310328
len -= 4;
311329
}
312-
buf4++;
313330
buf = (const unsigned char FAR *)buf4;
314331

315332
if (len) do {

0 commit comments

Comments
 (0)