Skip to content

Commit 515683c

Browse files
authored
Merge pull request libgit2#4567 from pks-t/pks/zlib-update
deps: upgrade embedded zlib to version 1.2.11
2 parents 2d2a602 + 4c5330c commit 515683c

File tree

15 files changed

+1816
-724
lines changed

15 files changed

+1816
-724
lines changed

deps/zlib/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
}

deps/zlib/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 <rbrown64@csc.com.au> 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)