Index: third_party/zlib/crc32.c |
diff --git a/third_party/zlib/crc32.c b/third_party/zlib/crc32.c |
index 09228ed9c76fbac076932fcf7c79214e10dd2bc5..9162429cc7b476d72e0bd994cf8549d2d695070d 100644 |
--- a/third_party/zlib/crc32.c |
+++ b/third_party/zlib/crc32.c |
@@ -1,5 +1,5 @@ |
/* crc32.c -- compute the CRC-32 of a data stream |
- * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler |
+ * Copyright (C) 1995-2006, 2010, 2011, 2012, 2016 Mark Adler |
* For conditions of distribution and use, see copyright notice in zlib.h |
* |
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster |
@@ -32,17 +32,15 @@ |
#include "x86.h" |
#include "zutil.h" /* for STDC and FAR definitions */ |
-#define local static |
- |
/* Definitions for doing the crc four data bytes at a time. */ |
#if !defined(NOBYFOUR) && defined(Z_U4) |
# define BYFOUR |
#endif |
#ifdef BYFOUR |
local unsigned long crc32_little OF((unsigned long, |
- const unsigned char FAR *, unsigned)); |
+ const unsigned char FAR *, z_size_t)); |
local unsigned long crc32_big OF((unsigned long, |
- const unsigned char FAR *, unsigned)); |
+ const unsigned char FAR *, z_size_t)); |
# define TBLS 8 |
#else |
# define TBLS 1 |
@@ -203,10 +201,10 @@ const z_crc_t FAR * ZEXPORT get_crc_table() |
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 |
/* ========================================================================= */ |
-unsigned long ZEXPORT crc32(crc, buf, len) |
+unsigned long ZEXPORT crc32_z(crc, buf, len) |
unsigned long crc; |
const unsigned char FAR *buf; |
- uInt len; |
+ z_size_t len; |
{ |
if (buf == Z_NULL) return 0UL; |
@@ -237,8 +235,29 @@ unsigned long ZEXPORT crc32(crc, buf, len) |
return crc ^ 0xffffffffUL; |
} |
+/* ========================================================================= */ |
+unsigned long ZEXPORT crc32(crc, buf, len) |
+ unsigned long crc; |
+ const unsigned char FAR *buf; |
+ uInt len; |
+{ |
+ return crc32_z(crc, buf, len); |
+} |
+ |
#ifdef BYFOUR |
+/* |
+ This BYFOUR code accesses the passed unsigned char * buffer with a 32-bit |
+ integer pointer type. This violates the strict aliasing rule, where a |
+ compiler can assume, for optimization purposes, that two pointers to |
+ fundamentally different types won't ever point to the same memory. This can |
+ manifest as a problem only if one of the pointers is written to. This code |
+ only reads from those pointers. So long as this code remains isolated in |
+ this compilation unit, there won't be a problem. For this reason, this code |
+ should not be copied and pasted into a compilation unit in which other code |
+ writes to the buffer that is passed to these routines. |
+ */ |
+ |
/* ========================================================================= */ |
#define DOLIT4 c ^= *buf4++; \ |
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ |
@@ -249,7 +268,7 @@ unsigned long ZEXPORT crc32(crc, buf, len) |
local unsigned long crc32_little(crc, buf, len) |
unsigned long crc; |
const unsigned char FAR *buf; |
- unsigned len; |
+ z_size_t len; |
{ |
register z_crc_t c; |
register const z_crc_t FAR *buf4; |
@@ -280,7 +299,7 @@ local unsigned long crc32_little(crc, buf, len) |
} |
/* ========================================================================= */ |
-#define DOBIG4 c ^= *++buf4; \ |
+#define DOBIG4 c ^= *buf4++; \ |
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ |
crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] |
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 |
@@ -289,7 +308,7 @@ local unsigned long crc32_little(crc, buf, len) |
local unsigned long crc32_big(crc, buf, len) |
unsigned long crc; |
const unsigned char FAR *buf; |
- unsigned len; |
+ z_size_t len; |
{ |
register z_crc_t c; |
register const z_crc_t FAR *buf4; |
@@ -302,7 +321,6 @@ local unsigned long crc32_big(crc, buf, len) |
} |
buf4 = (const z_crc_t FAR *)(const void FAR *)buf; |
- buf4--; |
while (len >= 32) { |
DOBIG32; |
len -= 32; |
@@ -311,7 +329,6 @@ local unsigned long crc32_big(crc, buf, len) |
DOBIG4; |
len -= 4; |
} |
- buf4++; |
buf = (const unsigned char FAR *)buf4; |
if (len) do { |