summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2012-08-12 18:08:52 -0700
committerMark Adler <madler@alumni.caltech.edu>2012-08-13 00:02:40 -0700
commit62d6112a7981ad7c34f3b43cffdf00d4662a4f25 (patch)
treeaed93070f7e1be31868dce1d62a1de6ffc1360f9
parentfb4e0599a5ddaef9eee726f786b9edef4943432b (diff)
downloadzlib-62d6112a7981ad7c34f3b43cffdf00d4662a4f25.tar.gz
zlib-62d6112a7981ad7c34f3b43cffdf00d4662a4f25.tar.bz2
zlib-62d6112a7981ad7c34f3b43cffdf00d4662a4f25.zip
Clean up the usage of z_const and respect const usage within zlib.
This patch allows zlib to compile cleanly with the -Wcast-qual gcc warning enabled, but only if ZLIB_CONST is defined, which adds const to next_in and msg in z_stream and in the in_func prototype. A --const option is added to ./configure which adds -DZLIB_CONST to the compile flags, and adds -Wcast-qual to the compile flags when ZLIBGCCWARN is set in the environment.
-rw-r--r--compress.c2
-rwxr-xr-xconfigure10
-rw-r--r--contrib/infback9/infback9.c2
-rw-r--r--deflate.c6
-rw-r--r--gzlib.c10
-rw-r--r--gzread.c3
-rw-r--r--gzwrite.c33
-rw-r--r--infback.c2
-rw-r--r--inffast.c4
-rw-r--r--inflate.c41
-rw-r--r--test/example.c8
-rw-r--r--trees.c14
-rw-r--r--uncompr.c2
-rw-r--r--zlib.h3
-rw-r--r--zutil.c2
-rw-r--r--zutil.h4
16 files changed, 76 insertions, 70 deletions
diff --git a/compress.c b/compress.c
index ea4dfbe..6e97626 100644
--- a/compress.c
+++ b/compress.c
@@ -29,7 +29,7 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
29 z_stream stream; 29 z_stream stream;
30 int err; 30 int err;
31 31
32 stream.next_in = (Bytef*)source; 32 stream.next_in = (z_const Bytef *)source;
33 stream.avail_in = (uInt)sourceLen; 33 stream.avail_in = (uInt)sourceLen;
34#ifdef MAXSEG_64K 34#ifdef MAXSEG_64K
35 /* Check for source > 64K on 16-bit machine: */ 35 /* Check for source > 64K on 16-bit machine: */
diff --git a/configure b/configure
index a69d7bf..bc39fd7 100755
--- a/configure
+++ b/configure
@@ -70,6 +70,7 @@ shared=1
70solo=0 70solo=0
71cover=0 71cover=0
72zprefix=0 72zprefix=0
73zconst=0
73build64=0 74build64=0
74gcc=0 75gcc=0
75old_cc="$CC" 76old_cc="$CC"
@@ -96,7 +97,7 @@ do
96case "$1" in 97case "$1" in
97 -h* | --help) 98 -h* | --help)
98 echo 'usage:' | tee -a configure.log 99 echo 'usage:' | tee -a configure.log
99 echo ' configure [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]' | tee -a configure.log 100 echo ' configure [--const] [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]' | tee -a configure.log
100 echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log 101 echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
101 echo ' [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log 102 echo ' [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
102 exit 0 ;; 103 exit 0 ;;
@@ -119,6 +120,7 @@ case "$1" in
119 -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;; 120 -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
120 --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;; 121 --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
121 --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;; 122 --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
123 -c* | --const) zconst=1; shift ;;
122 *) 124 *)
123 echo "unknown option: $1" | tee -a configure.log 125 echo "unknown option: $1" | tee -a configure.log
124 echo "$0 --help for help" | tee -a configure.log 126 echo "$0 --help for help" | tee -a configure.log
@@ -171,7 +173,11 @@ if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then
171 SFLAGS="${SFLAGS} -m64" 173 SFLAGS="${SFLAGS} -m64"
172 fi 174 fi
173 if test "${ZLIBGCCWARN}" = "YES"; then 175 if test "${ZLIBGCCWARN}" = "YES"; then
174 CFLAGS="${CFLAGS} -Wall -Wextra -pedantic" 176 if test "$zconst" -eq 1; then
177 CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual -pedantic -DZLIB_CONST"
178 else
179 CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
180 fi
175 fi 181 fi
176 if test -z "$uname"; then 182 if test -z "$uname"; then
177 uname=`(uname -s || echo unknown) 2>/dev/null` 183 uname=`(uname -s || echo unknown) 2>/dev/null`
diff --git a/contrib/infback9/infback9.c b/contrib/infback9/infback9.c
index 3691d4a..05fb3e3 100644
--- a/contrib/infback9/infback9.c
+++ b/contrib/infback9/infback9.c
@@ -222,7 +222,7 @@ out_func out;
222void FAR *out_desc; 222void FAR *out_desc;
223{ 223{
224 struct inflate_state FAR *state; 224 struct inflate_state FAR *state;
225 unsigned char FAR *next; /* next input */ 225 z_const unsigned char FAR *next; /* next input */
226 unsigned char FAR *put; /* next output */ 226 unsigned char FAR *put; /* next output */
227 unsigned have; /* available input */ 227 unsigned have; /* available input */
228 unsigned long left; /* available output */ 228 unsigned long left; /* available output */
diff --git a/deflate.c b/deflate.c
index 4792345..4aa5afb 100644
--- a/deflate.c
+++ b/deflate.c
@@ -305,7 +305,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
305 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || 305 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
306 s->pending_buf == Z_NULL) { 306 s->pending_buf == Z_NULL) {
307 s->status = FINISH_STATE; 307 s->status = FINISH_STATE;
308 strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); 308 strm->msg = ERR_MSG(Z_MEM_ERROR);
309 deflateEnd (strm); 309 deflateEnd (strm);
310 return Z_MEM_ERROR; 310 return Z_MEM_ERROR;
311 } 311 }
@@ -329,7 +329,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
329 uInt str, n; 329 uInt str, n;
330 int wrap; 330 int wrap;
331 unsigned avail; 331 unsigned avail;
332 unsigned char *next; 332 z_const unsigned char *next;
333 333
334 if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) 334 if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
335 return Z_STREAM_ERROR; 335 return Z_STREAM_ERROR;
@@ -359,7 +359,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
359 avail = strm->avail_in; 359 avail = strm->avail_in;
360 next = strm->next_in; 360 next = strm->next_in;
361 strm->avail_in = dictLength; 361 strm->avail_in = dictLength;
362 strm->next_in = (Bytef *)dictionary; 362 strm->next_in = (z_const Bytef *)dictionary;
363 fill_window(s); 363 fill_window(s);
364 while (s->lookahead >= MIN_MATCH) { 364 while (s->lookahead >= MIN_MATCH) {
365 str = s->strstart; 365 str = s->strstart;
diff --git a/gzlib.c b/gzlib.c
index c10fabb..e4ca576 100644
--- a/gzlib.c
+++ b/gzlib.c
@@ -541,7 +541,8 @@ const char * ZEXPORT gzerror(file, errnum)
541 /* return error information */ 541 /* return error information */
542 if (errnum != NULL) 542 if (errnum != NULL)
543 *errnum = state->err; 543 *errnum = state->err;
544 return state->msg == NULL ? "" : state->msg; 544 return state->err == Z_MEM_ERROR ? "out of memory" :
545 (state->msg == NULL ? "" : state->msg);
545} 546}
546 547
547/* -- see zlib.h -- */ 548/* -- see zlib.h -- */
@@ -592,16 +593,13 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
592 if (msg == NULL) 593 if (msg == NULL)
593 return; 594 return;
594 595
595 /* for an out of memory error, save as static string */ 596 /* for an out of memory error, return literal string when requested */
596 if (err == Z_MEM_ERROR) { 597 if (err == Z_MEM_ERROR)
597 state->msg = (char *)msg;
598 return; 598 return;
599 }
600 599
601 /* construct error message with path */ 600 /* construct error message with path */
602 if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { 601 if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
603 state->err = Z_MEM_ERROR; 602 state->err = Z_MEM_ERROR;
604 state->msg = (char *)"out of memory";
605 return; 603 return;
606 } 604 }
607#if !defined(NO_snprintf) && !defined(NO_vsnprintf) 605#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
diff --git a/gzread.c b/gzread.c
index 8ace830..52985c9 100644
--- a/gzread.c
+++ b/gzread.c
@@ -58,7 +58,8 @@ local int gz_avail(state)
58 return -1; 58 return -1;
59 if (state->eof == 0) { 59 if (state->eof == 0) {
60 if (strm->avail_in) { /* copy what's there to the start */ 60 if (strm->avail_in) { /* copy what's there to the start */
61 unsigned char *p = state->in, *q = strm->next_in; 61 unsigned char *p = state->in;
62 unsigned const char *q = strm->next_in;
62 unsigned n = strm->avail_in; 63 unsigned n = strm->avail_in;
63 do { 64 do {
64 *p++ = *q++; 65 *p++ = *q++;
diff --git a/gzwrite.c b/gzwrite.c
index 27cb342..bf57913 100644
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -168,7 +168,6 @@ int ZEXPORT gzwrite(file, buf, len)
168 unsigned len; 168 unsigned len;
169{ 169{
170 unsigned put = len; 170 unsigned put = len;
171 unsigned n;
172 gz_statep state; 171 gz_statep state;
173 z_streamp strm; 172 z_streamp strm;
174 173
@@ -208,16 +207,19 @@ int ZEXPORT gzwrite(file, buf, len)
208 if (len < state->size) { 207 if (len < state->size) {
209 /* copy to input buffer, compress when full */ 208 /* copy to input buffer, compress when full */
210 do { 209 do {
210 unsigned have, copy;
211
211 if (strm->avail_in == 0) 212 if (strm->avail_in == 0)
212 strm->next_in = state->in; 213 strm->next_in = state->in;
213 n = state->size - strm->avail_in; 214 have = strm->next_in + strm->avail_in - state->in;
214 if (n > len) 215 copy = state->size - have;
215 n = len; 216 if (copy > len)
216 memcpy(strm->next_in + strm->avail_in, buf, n); 217 copy = len;
217 strm->avail_in += n; 218 memcpy(state->in + have, buf, copy);
218 state->x.pos += n; 219 strm->avail_in += copy;
219 buf = (char *)buf + n; 220 state->x.pos += copy;
220 len -= n; 221 buf = (const char *)buf + copy;
222 len -= copy;
221 if (len && gz_comp(state, Z_NO_FLUSH) == -1) 223 if (len && gz_comp(state, Z_NO_FLUSH) == -1)
222 return 0; 224 return 0;
223 } while (len); 225 } while (len);
@@ -229,7 +231,7 @@ int ZEXPORT gzwrite(file, buf, len)
229 231
230 /* directly compress user buffer to file */ 232 /* directly compress user buffer to file */
231 strm->avail_in = len; 233 strm->avail_in = len;
232 strm->next_in = (voidp)buf; 234 strm->next_in = (z_const Bytef *)buf;
233 state->x.pos += len; 235 state->x.pos += len;
234 if (gz_comp(state, Z_NO_FLUSH) == -1) 236 if (gz_comp(state, Z_NO_FLUSH) == -1)
235 return 0; 237 return 0;
@@ -244,6 +246,7 @@ int ZEXPORT gzputc(file, c)
244 gzFile file; 246 gzFile file;
245 int c; 247 int c;
246{ 248{
249 unsigned have;
247 unsigned char buf[1]; 250 unsigned char buf[1];
248 gz_statep state; 251 gz_statep state;
249 z_streamp strm; 252 z_streamp strm;
@@ -267,10 +270,12 @@ int ZEXPORT gzputc(file, c)
267 270
268 /* try writing to input buffer for speed (state->size == 0 if buffer not 271 /* try writing to input buffer for speed (state->size == 0 if buffer not
269 initialized) */ 272 initialized) */
270 if (strm->avail_in < state->size) { 273 if (strm->avail_in == 0)
271 if (strm->avail_in == 0) 274 strm->next_in = state->in;
272 strm->next_in = state->in; 275 have = strm->next_in + strm->avail_in - state->in;
273 strm->next_in[strm->avail_in++] = c; 276 if (have < state->size) {
277 state->in[have] = c;
278 strm->avail_in++;
274 state->x.pos++; 279 state->x.pos++;
275 return c & 0xff; 280 return c & 0xff;
276 } 281 }
diff --git a/infback.c b/infback.c
index 981aff1..f3833c2 100644
--- a/infback.c
+++ b/infback.c
@@ -255,7 +255,7 @@ out_func out;
255void FAR *out_desc; 255void FAR *out_desc;
256{ 256{
257 struct inflate_state FAR *state; 257 struct inflate_state FAR *state;
258 unsigned char FAR *next; /* next input */ 258 z_const unsigned char FAR *next; /* next input */
259 unsigned char FAR *put; /* next output */ 259 unsigned char FAR *put; /* next output */
260 unsigned have, left; /* available input and output */ 260 unsigned have, left; /* available input and output */
261 unsigned long hold; /* bit buffer */ 261 unsigned long hold; /* bit buffer */
diff --git a/inffast.c b/inffast.c
index 2f1d60b..0d78f23 100644
--- a/inffast.c
+++ b/inffast.c
@@ -69,8 +69,8 @@ z_streamp strm;
69unsigned start; /* inflate()'s starting value for strm->avail_out */ 69unsigned start; /* inflate()'s starting value for strm->avail_out */
70{ 70{
71 struct inflate_state FAR *state; 71 struct inflate_state FAR *state;
72 unsigned char FAR *in; /* local strm->next_in */ 72 z_const unsigned char FAR *in; /* local strm->next_in */
73 unsigned char FAR *last; /* while in < last, enough input available */ 73 z_const unsigned char FAR *last; /* while in < last, enough input available */
74 unsigned char FAR *out; /* local strm->next_out */ 74 unsigned char FAR *out; /* local strm->next_out */
75 unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ 75 unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
76 unsigned char FAR *end; /* while out < end, enough space available */ 76 unsigned char FAR *end; /* while out < end, enough space available */
diff --git a/inflate.c b/inflate.c
index d1efdb8..870f89b 100644
--- a/inflate.c
+++ b/inflate.c
@@ -93,11 +93,12 @@
93 93
94/* function prototypes */ 94/* function prototypes */
95local void fixedtables OF((struct inflate_state FAR *state)); 95local void fixedtables OF((struct inflate_state FAR *state));
96local int updatewindow OF((z_streamp strm, unsigned out)); 96local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
97 unsigned copy));
97#ifdef BUILDFIXED 98#ifdef BUILDFIXED
98 void makefixed OF((void)); 99 void makefixed OF((void));
99#endif 100#endif
100local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, 101local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
101 unsigned len)); 102 unsigned len));
102 103
103int ZEXPORT inflateResetKeep(strm) 104int ZEXPORT inflateResetKeep(strm)
@@ -375,12 +376,13 @@ void makefixed()
375 output will fall in the output data, making match copies simpler and faster. 376 output will fall in the output data, making match copies simpler and faster.
376 The advantage may be dependent on the size of the processor's data caches. 377 The advantage may be dependent on the size of the processor's data caches.
377 */ 378 */
378local int updatewindow(strm, out) 379local int updatewindow(strm, end, copy)
379z_streamp strm; 380z_streamp strm;
380unsigned out; 381const Bytef *end;
382unsigned copy;
381{ 383{
382 struct inflate_state FAR *state; 384 struct inflate_state FAR *state;
383 unsigned copy, dist; 385 unsigned dist;
384 386
385 state = (struct inflate_state FAR *)strm->state; 387 state = (struct inflate_state FAR *)strm->state;
386 388
@@ -400,19 +402,18 @@ unsigned out;
400 } 402 }
401 403
402 /* copy state->wsize or less output bytes into the circular window */ 404 /* copy state->wsize or less output bytes into the circular window */
403 copy = out - strm->avail_out;
404 if (copy >= state->wsize) { 405 if (copy >= state->wsize) {
405 zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); 406 zmemcpy(state->window, end - state->wsize, state->wsize);
406 state->wnext = 0; 407 state->wnext = 0;
407 state->whave = state->wsize; 408 state->whave = state->wsize;
408 } 409 }
409 else { 410 else {
410 dist = state->wsize - state->wnext; 411 dist = state->wsize - state->wnext;
411 if (dist > copy) dist = copy; 412 if (dist > copy) dist = copy;
412 zmemcpy(state->window + state->wnext, strm->next_out - copy, dist); 413 zmemcpy(state->window + state->wnext, end - copy, dist);
413 copy -= dist; 414 copy -= dist;
414 if (copy) { 415 if (copy) {
415 zmemcpy(state->window, strm->next_out - copy, copy); 416 zmemcpy(state->window, end - copy, copy);
416 state->wnext = copy; 417 state->wnext = copy;
417 state->whave = state->wsize; 418 state->whave = state->wsize;
418 } 419 }
@@ -606,7 +607,7 @@ z_streamp strm;
606int flush; 607int flush;
607{ 608{
608 struct inflate_state FAR *state; 609 struct inflate_state FAR *state;
609 unsigned char FAR *next; /* next input */ 610 z_const unsigned char FAR *next; /* next input */
610 unsigned char FAR *put; /* next output */ 611 unsigned char FAR *put; /* next output */
611 unsigned have, left; /* available input and output */ 612 unsigned have, left; /* available input and output */
612 unsigned long hold; /* bit buffer */ 613 unsigned long hold; /* bit buffer */
@@ -920,7 +921,7 @@ int flush;
920 while (state->have < 19) 921 while (state->have < 19)
921 state->lens[order[state->have++]] = 0; 922 state->lens[order[state->have++]] = 0;
922 state->next = state->codes; 923 state->next = state->codes;
923 state->lencode = (code const FAR *)(state->next); 924 state->lencode = (const code FAR *)(state->next);
924 state->lenbits = 7; 925 state->lenbits = 7;
925 ret = inflate_table(CODES, state->lens, 19, &(state->next), 926 ret = inflate_table(CODES, state->lens, 19, &(state->next),
926 &(state->lenbits), state->work); 927 &(state->lenbits), state->work);
@@ -994,7 +995,7 @@ int flush;
994 values here (9 and 6) without reading the comments in inftrees.h 995 values here (9 and 6) without reading the comments in inftrees.h
995 concerning the ENOUGH constants, which depend on those values */ 996 concerning the ENOUGH constants, which depend on those values */
996 state->next = state->codes; 997 state->next = state->codes;
997 state->lencode = (code const FAR *)(state->next); 998 state->lencode = (const code FAR *)(state->next);
998 state->lenbits = 9; 999 state->lenbits = 9;
999 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), 1000 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1000 &(state->lenbits), state->work); 1001 &(state->lenbits), state->work);
@@ -1003,7 +1004,7 @@ int flush;
1003 state->mode = BAD; 1004 state->mode = BAD;
1004 break; 1005 break;
1005 } 1006 }
1006 state->distcode = (code const FAR *)(state->next); 1007 state->distcode = (const code FAR *)(state->next);
1007 state->distbits = 6; 1008 state->distbits = 6;
1008 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, 1009 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
1009 &(state->next), &(state->distbits), state->work); 1010 &(state->next), &(state->distbits), state->work);
@@ -1230,7 +1231,7 @@ int flush;
1230 RESTORE(); 1231 RESTORE();
1231 if (state->wsize || (out != strm->avail_out && state->mode < BAD && 1232 if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
1232 (state->mode < CHECK || flush != Z_FINISH))) 1233 (state->mode < CHECK || flush != Z_FINISH)))
1233 if (updatewindow(strm, out)) { 1234 if (updatewindow(strm, strm->next_out, out - strm->avail_out)) {
1234 state->mode = MEM; 1235 state->mode = MEM;
1235 return Z_MEM_ERROR; 1236 return Z_MEM_ERROR;
1236 } 1237 }
@@ -1294,8 +1295,6 @@ uInt dictLength;
1294{ 1295{
1295 struct inflate_state FAR *state; 1296 struct inflate_state FAR *state;
1296 unsigned long dictid; 1297 unsigned long dictid;
1297 unsigned char *next;
1298 unsigned avail;
1299 int ret; 1298 int ret;
1300 1299
1301 /* check state */ 1300 /* check state */
@@ -1314,13 +1313,7 @@ uInt dictLength;
1314 1313
1315 /* copy dictionary to window using updatewindow(), which will amend the 1314 /* copy dictionary to window using updatewindow(), which will amend the
1316 existing dictionary if appropriate */ 1315 existing dictionary if appropriate */
1317 next = strm->next_out; 1316 ret = updatewindow(strm, dictionary + dictLength, dictLength);
1318 avail = strm->avail_out;
1319 strm->next_out = (Bytef *)dictionary + dictLength;
1320 strm->avail_out = 0;
1321 ret = updatewindow(strm, dictLength);
1322 strm->avail_out = avail;
1323 strm->next_out = next;
1324 if (ret) { 1317 if (ret) {
1325 state->mode = MEM; 1318 state->mode = MEM;
1326 return Z_MEM_ERROR; 1319 return Z_MEM_ERROR;
@@ -1360,7 +1353,7 @@ gz_headerp head;
1360 */ 1353 */
1361local unsigned syncsearch(have, buf, len) 1354local unsigned syncsearch(have, buf, len)
1362unsigned FAR *have; 1355unsigned FAR *have;
1363unsigned char FAR *buf; 1356const unsigned char FAR *buf;
1364unsigned len; 1357unsigned len;
1365{ 1358{
1366 unsigned got; 1359 unsigned got;
diff --git a/test/example.c b/test/example.c
index f515a48..138a699 100644
--- a/test/example.c
+++ b/test/example.c
@@ -26,7 +26,7 @@
26 } \ 26 } \
27} 27}
28 28
29const char hello[] = "hello, hello!"; 29z_const char hello[] = "hello, hello!";
30/* "hello world" would be more standard, but the repeated "hello" 30/* "hello world" would be more standard, but the repeated "hello"
31 * stresses the compression code better, sorry... 31 * stresses the compression code better, sorry...
32 */ 32 */
@@ -212,7 +212,7 @@ void test_deflate(compr, comprLen)
212 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); 212 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
213 CHECK_ERR(err, "deflateInit"); 213 CHECK_ERR(err, "deflateInit");
214 214
215 c_stream.next_in = (Bytef*)hello; 215 c_stream.next_in = (z_const unsigned char *)hello;
216 c_stream.next_out = compr; 216 c_stream.next_out = compr;
217 217
218 while (c_stream.total_in != len && c_stream.total_out < comprLen) { 218 while (c_stream.total_in != len && c_stream.total_out < comprLen) {
@@ -387,7 +387,7 @@ void test_flush(compr, comprLen)
387 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); 387 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
388 CHECK_ERR(err, "deflateInit"); 388 CHECK_ERR(err, "deflateInit");
389 389
390 c_stream.next_in = (Bytef*)hello; 390 c_stream.next_in = (z_const unsigned char *)hello;
391 c_stream.next_out = compr; 391 c_stream.next_out = compr;
392 c_stream.avail_in = 3; 392 c_stream.avail_in = 3;
393 c_stream.avail_out = (uInt)*comprLen; 393 c_stream.avail_out = (uInt)*comprLen;
@@ -476,7 +476,7 @@ void test_dict_deflate(compr, comprLen)
476 c_stream.next_out = compr; 476 c_stream.next_out = compr;
477 c_stream.avail_out = (uInt)comprLen; 477 c_stream.avail_out = (uInt)comprLen;
478 478
479 c_stream.next_in = (Bytef*)hello; 479 c_stream.next_in = (z_const unsigned char *)hello;
480 c_stream.avail_in = (uInt)strlen(hello)+1; 480 c_stream.avail_in = (uInt)strlen(hello)+1;
481 481
482 err = deflate(&c_stream, Z_FINISH); 482 err = deflate(&c_stream, Z_FINISH);
diff --git a/trees.c b/trees.c
index 8c32b21..1fd7759 100644
--- a/trees.c
+++ b/trees.c
@@ -146,8 +146,8 @@ local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
146local int build_bl_tree OF((deflate_state *s)); 146local int build_bl_tree OF((deflate_state *s));
147local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, 147local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
148 int blcodes)); 148 int blcodes));
149local void compress_block OF((deflate_state *s, ct_data *ltree, 149local void compress_block OF((deflate_state *s, const ct_data *ltree,
150 ct_data *dtree)); 150 const ct_data *dtree));
151local int detect_data_type OF((deflate_state *s)); 151local int detect_data_type OF((deflate_state *s));
152local unsigned bi_reverse OF((unsigned value, int length)); 152local unsigned bi_reverse OF((unsigned value, int length));
153local void bi_windup OF((deflate_state *s)); 153local void bi_windup OF((deflate_state *s));
@@ -972,7 +972,8 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
972 } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { 972 } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
973#endif 973#endif
974 send_bits(s, (STATIC_TREES<<1)+last, 3); 974 send_bits(s, (STATIC_TREES<<1)+last, 3);
975 compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); 975 compress_block(s, (const ct_data *)static_ltree,
976 (const ct_data *)static_dtree);
976#ifdef DEBUG 977#ifdef DEBUG
977 s->compressed_len += 3 + s->static_len; 978 s->compressed_len += 3 + s->static_len;
978#endif 979#endif
@@ -980,7 +981,8 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
980 send_bits(s, (DYN_TREES<<1)+last, 3); 981 send_bits(s, (DYN_TREES<<1)+last, 3);
981 send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, 982 send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
982 max_blindex+1); 983 max_blindex+1);
983 compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); 984 compress_block(s, (const ct_data *)s->dyn_ltree,
985 (const ct_data *)s->dyn_dtree);
984#ifdef DEBUG 986#ifdef DEBUG
985 s->compressed_len += 3 + s->opt_len; 987 s->compressed_len += 3 + s->opt_len;
986#endif 988#endif
@@ -1057,8 +1059,8 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
1057 */ 1059 */
1058local void compress_block(s, ltree, dtree) 1060local void compress_block(s, ltree, dtree)
1059 deflate_state *s; 1061 deflate_state *s;
1060 ct_data *ltree; /* literal tree */ 1062 const ct_data *ltree; /* literal tree */
1061 ct_data *dtree; /* distance tree */ 1063 const ct_data *dtree; /* distance tree */
1062{ 1064{
1063 unsigned dist; /* distance of matched string */ 1065 unsigned dist; /* distance of matched string */
1064 int lc; /* match length or unmatched char (if dist == 0) */ 1066 int lc; /* match length or unmatched char (if dist == 0) */
diff --git a/uncompr.c b/uncompr.c
index ad98be3..242e949 100644
--- a/uncompr.c
+++ b/uncompr.c
@@ -30,7 +30,7 @@ int ZEXPORT uncompress (dest, destLen, source, sourceLen)
30 z_stream stream; 30 z_stream stream;
31 int err; 31 int err;
32 32
33 stream.next_in = (Bytef*)source; 33 stream.next_in = (z_const Bytef *)source;
34 stream.avail_in = (uInt)sourceLen; 34 stream.avail_in = (uInt)sourceLen;
35 /* Check for source > 64K on 16-bit machine: */ 35 /* Check for source > 64K on 16-bit machine: */
36 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 36 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
diff --git a/zlib.h b/zlib.h
index cd47df5..55e3c2c 100644
--- a/zlib.h
+++ b/zlib.h
@@ -1022,7 +1022,8 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
1022 the version of the header file. 1022 the version of the header file.
1023*/ 1023*/
1024 1024
1025typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); 1025typedef unsigned (*in_func) OF((void FAR *,
1026 z_const unsigned char FAR * FAR *));
1026typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); 1027typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
1027 1028
1028ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, 1029ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
diff --git a/zutil.c b/zutil.c
index 65e0d3b..23d2ebe 100644
--- a/zutil.c
+++ b/zutil.c
@@ -14,7 +14,7 @@
14struct internal_state {int dummy;}; /* for buggy compilers */ 14struct internal_state {int dummy;}; /* for buggy compilers */
15#endif 15#endif
16 16
17const char * const z_errmsg[10] = { 17z_const char * const z_errmsg[10] = {
18"need dictionary", /* Z_NEED_DICT 2 */ 18"need dictionary", /* Z_NEED_DICT 2 */
19"stream end", /* Z_STREAM_END 1 */ 19"stream end", /* Z_STREAM_END 1 */
20"", /* Z_OK 0 */ 20"", /* Z_OK 0 */
diff --git a/zutil.h b/zutil.h
index 4e3dcc6..0f02cbe 100644
--- a/zutil.h
+++ b/zutil.h
@@ -44,13 +44,13 @@ typedef unsigned short ush;
44typedef ush FAR ushf; 44typedef ush FAR ushf;
45typedef unsigned long ulg; 45typedef unsigned long ulg;
46 46
47extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 47extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
48/* (size given to avoid silly warnings with Visual C++) */ 48/* (size given to avoid silly warnings with Visual C++) */
49 49
50#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 50#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
51 51
52#define ERR_RETURN(strm,err) \ 52#define ERR_RETURN(strm,err) \
53 return (strm->msg = (char*)ERR_MSG(err), (err)) 53 return (strm->msg = ERR_MSG(err), (err))
54/* To be used only when the state is known to be valid */ 54/* To be used only when the state is known to be valid */
55 55
56 /* common constants */ 56 /* common constants */