summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2017-06-03 09:49:39 -0700
committerMark Adler <madler@alumni.caltech.edu>2017-06-03 09:53:33 -0700
commit3c46f5ddb5d4c6203805209076249dd80589682b (patch)
treeedfdce5921b4009afc0f0d352f324a00da859d69
parent44e8ac810d7d50381429a15cdc6e48816beafd2b (diff)
downloadzlib-3c46f5ddb5d4c6203805209076249dd80589682b.tar.gz
zlib-3c46f5ddb5d4c6203805209076249dd80589682b.tar.bz2
zlib-3c46f5ddb5d4c6203805209076249dd80589682b.zip
Avoid the use of ptrdiff_t.
This isn't the right type anyway to assure that it contains a pointer. That type would be intptr_t or uintptr_t. However the C99 standard says that those types are optional, so their use would not be portable. This commit simply uses size_t or whatever configure decided to use for size_t. That would be the same length as ptrdiff_t, and so will work just as well. The code checks to see if the length of the type used is the same as the length of a void pointer, so there is already protection against the use of the wrong type. The use of size_t (or ptrdiff_t) will almost always work, as all modern architectures have an array size that is the same as the pointer size. Only old segmented architectures would have to fall back to the slower CRC-32 calculation, where the amount of memory that can be accessed is larger than the maximum array size.
-rw-r--r--crc32.c6
-rw-r--r--zutil.h8
2 files changed, 3 insertions, 11 deletions
diff --git a/crc32.c b/crc32.c
index 9580440..e72636a 100644
--- a/crc32.c
+++ b/crc32.c
@@ -212,7 +212,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
212#endif /* DYNAMIC_CRC_TABLE */ 212#endif /* DYNAMIC_CRC_TABLE */
213 213
214#ifdef BYFOUR 214#ifdef BYFOUR
215 if (sizeof(void *) == sizeof(ptrdiff_t)) { 215 if (sizeof(void *) == sizeof(z_size_t)) {
216 z_crc_t endian; 216 z_crc_t endian;
217 217
218 endian = 1; 218 endian = 1;
@@ -273,7 +273,7 @@ local unsigned long crc32_little(crc, buf, len)
273 273
274 c = (z_crc_t)crc; 274 c = (z_crc_t)crc;
275 c = ~c; 275 c = ~c;
276 while (len && ((ptrdiff_t)buf & 3)) { 276 while (len && ((z_size_t)buf & 3)) {
277 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 277 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
278 len--; 278 len--;
279 } 279 }
@@ -313,7 +313,7 @@ local unsigned long crc32_big(crc, buf, len)
313 313
314 c = ZSWAP32((z_crc_t)crc); 314 c = ZSWAP32((z_crc_t)crc);
315 c = ~c; 315 c = ~c;
316 while (len && ((ptrdiff_t)buf & 3)) { 316 while (len && ((z_size_t)buf & 3)) {
317 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 317 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
318 len--; 318 len--;
319 } 319 }
diff --git a/zutil.h b/zutil.h
index b079ea6..60a0bca 100644
--- a/zutil.h
+++ b/zutil.h
@@ -29,10 +29,6 @@
29# include <stdlib.h> 29# include <stdlib.h>
30#endif 30#endif
31 31
32#ifdef Z_SOLO
33 typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
34#endif
35
36#ifndef local 32#ifndef local
37# define local static 33# define local static
38#endif 34#endif
@@ -170,10 +166,6 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
170#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX 166#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
171# if defined(_WIN32_WCE) 167# if defined(_WIN32_WCE)
172# define fdopen(fd,mode) NULL /* No fdopen() */ 168# define fdopen(fd,mode) NULL /* No fdopen() */
173# ifndef _PTRDIFF_T_DEFINED
174 typedef int ptrdiff_t;
175# define _PTRDIFF_T_DEFINED
176# endif
177# else 169# else
178# define fdopen(fd,type) _fdopen(fd,type) 170# define fdopen(fd,type) _fdopen(fd,type)
179# endif 171# endif