提交 62d6112a 编写于 作者: M Mark Adler

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.
上级 fb4e0599
...@@ -29,7 +29,7 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) ...@@ -29,7 +29,7 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
z_stream stream; z_stream stream;
int err; int err;
stream.next_in = (Bytef*)source; stream.next_in = (z_const Bytef *)source;
stream.avail_in = (uInt)sourceLen; stream.avail_in = (uInt)sourceLen;
#ifdef MAXSEG_64K #ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */ /* Check for source > 64K on 16-bit machine: */
......
...@@ -70,6 +70,7 @@ shared=1 ...@@ -70,6 +70,7 @@ shared=1
solo=0 solo=0
cover=0 cover=0
zprefix=0 zprefix=0
zconst=0
build64=0 build64=0
gcc=0 gcc=0
old_cc="$CC" old_cc="$CC"
...@@ -96,7 +97,7 @@ do ...@@ -96,7 +97,7 @@ do
case "$1" in case "$1" in
-h* | --help) -h* | --help)
echo 'usage:' | tee -a configure.log echo 'usage:' | tee -a configure.log
echo ' configure [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]' | tee -a configure.log echo ' configure [--const] [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]' | tee -a configure.log
echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
echo ' [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log echo ' [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
exit 0 ;; exit 0 ;;
...@@ -119,6 +120,7 @@ case "$1" in ...@@ -119,6 +120,7 @@ case "$1" in
-a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;; -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
--sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;; --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
--localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;; --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
-c* | --const) zconst=1; shift ;;
*) *)
echo "unknown option: $1" | tee -a configure.log echo "unknown option: $1" | tee -a configure.log
echo "$0 --help for help" | tee -a configure.log 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,7 +173,11 @@ if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then
SFLAGS="${SFLAGS} -m64" SFLAGS="${SFLAGS} -m64"
fi fi
if test "${ZLIBGCCWARN}" = "YES"; then if test "${ZLIBGCCWARN}" = "YES"; then
CFLAGS="${CFLAGS} -Wall -Wextra -pedantic" if test "$zconst" -eq 1; then
CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual -pedantic -DZLIB_CONST"
else
CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
fi
fi fi
if test -z "$uname"; then if test -z "$uname"; then
uname=`(uname -s || echo unknown) 2>/dev/null` uname=`(uname -s || echo unknown) 2>/dev/null`
......
...@@ -222,7 +222,7 @@ out_func out; ...@@ -222,7 +222,7 @@ out_func out;
void FAR *out_desc; void FAR *out_desc;
{ {
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned char FAR *next; /* next input */ z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */ unsigned char FAR *put; /* next output */
unsigned have; /* available input */ unsigned have; /* available input */
unsigned long left; /* available output */ unsigned long left; /* available output */
......
...@@ -305,7 +305,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, ...@@ -305,7 +305,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
s->pending_buf == Z_NULL) { s->pending_buf == Z_NULL) {
s->status = FINISH_STATE; s->status = FINISH_STATE;
strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); strm->msg = ERR_MSG(Z_MEM_ERROR);
deflateEnd (strm); deflateEnd (strm);
return Z_MEM_ERROR; return Z_MEM_ERROR;
} }
...@@ -329,7 +329,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) ...@@ -329,7 +329,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
uInt str, n; uInt str, n;
int wrap; int wrap;
unsigned avail; unsigned avail;
unsigned char *next; z_const unsigned char *next;
if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
...@@ -359,7 +359,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) ...@@ -359,7 +359,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
avail = strm->avail_in; avail = strm->avail_in;
next = strm->next_in; next = strm->next_in;
strm->avail_in = dictLength; strm->avail_in = dictLength;
strm->next_in = (Bytef *)dictionary; strm->next_in = (z_const Bytef *)dictionary;
fill_window(s); fill_window(s);
while (s->lookahead >= MIN_MATCH) { while (s->lookahead >= MIN_MATCH) {
str = s->strstart; str = s->strstart;
......
...@@ -541,7 +541,8 @@ const char * ZEXPORT gzerror(file, errnum) ...@@ -541,7 +541,8 @@ const char * ZEXPORT gzerror(file, errnum)
/* return error information */ /* return error information */
if (errnum != NULL) if (errnum != NULL)
*errnum = state->err; *errnum = state->err;
return state->msg == NULL ? "" : state->msg; return state->err == Z_MEM_ERROR ? "out of memory" :
(state->msg == NULL ? "" : state->msg);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
...@@ -592,16 +593,13 @@ void ZLIB_INTERNAL gz_error(state, err, msg) ...@@ -592,16 +593,13 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
if (msg == NULL) if (msg == NULL)
return; return;
/* for an out of memory error, save as static string */ /* for an out of memory error, return literal string when requested */
if (err == Z_MEM_ERROR) { if (err == Z_MEM_ERROR)
state->msg = (char *)msg;
return; return;
}
/* construct error message with path */ /* construct error message with path */
if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
state->err = Z_MEM_ERROR; state->err = Z_MEM_ERROR;
state->msg = (char *)"out of memory";
return; return;
} }
#if !defined(NO_snprintf) && !defined(NO_vsnprintf) #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
......
...@@ -58,7 +58,8 @@ local int gz_avail(state) ...@@ -58,7 +58,8 @@ local int gz_avail(state)
return -1; return -1;
if (state->eof == 0) { if (state->eof == 0) {
if (strm->avail_in) { /* copy what's there to the start */ if (strm->avail_in) { /* copy what's there to the start */
unsigned char *p = state->in, *q = strm->next_in; unsigned char *p = state->in;
unsigned const char *q = strm->next_in;
unsigned n = strm->avail_in; unsigned n = strm->avail_in;
do { do {
*p++ = *q++; *p++ = *q++;
......
...@@ -168,7 +168,6 @@ int ZEXPORT gzwrite(file, buf, len) ...@@ -168,7 +168,6 @@ int ZEXPORT gzwrite(file, buf, len)
unsigned len; unsigned len;
{ {
unsigned put = len; unsigned put = len;
unsigned n;
gz_statep state; gz_statep state;
z_streamp strm; z_streamp strm;
...@@ -208,16 +207,19 @@ int ZEXPORT gzwrite(file, buf, len) ...@@ -208,16 +207,19 @@ int ZEXPORT gzwrite(file, buf, len)
if (len < state->size) { if (len < state->size) {
/* copy to input buffer, compress when full */ /* copy to input buffer, compress when full */
do { do {
unsigned have, copy;
if (strm->avail_in == 0) if (strm->avail_in == 0)
strm->next_in = state->in; strm->next_in = state->in;
n = state->size - strm->avail_in; have = strm->next_in + strm->avail_in - state->in;
if (n > len) copy = state->size - have;
n = len; if (copy > len)
memcpy(strm->next_in + strm->avail_in, buf, n); copy = len;
strm->avail_in += n; memcpy(state->in + have, buf, copy);
state->x.pos += n; strm->avail_in += copy;
buf = (char *)buf + n; state->x.pos += copy;
len -= n; buf = (const char *)buf + copy;
len -= copy;
if (len && gz_comp(state, Z_NO_FLUSH) == -1) if (len && gz_comp(state, Z_NO_FLUSH) == -1)
return 0; return 0;
} while (len); } while (len);
...@@ -229,7 +231,7 @@ int ZEXPORT gzwrite(file, buf, len) ...@@ -229,7 +231,7 @@ int ZEXPORT gzwrite(file, buf, len)
/* directly compress user buffer to file */ /* directly compress user buffer to file */
strm->avail_in = len; strm->avail_in = len;
strm->next_in = (voidp)buf; strm->next_in = (z_const Bytef *)buf;
state->x.pos += len; state->x.pos += len;
if (gz_comp(state, Z_NO_FLUSH) == -1) if (gz_comp(state, Z_NO_FLUSH) == -1)
return 0; return 0;
...@@ -244,6 +246,7 @@ int ZEXPORT gzputc(file, c) ...@@ -244,6 +246,7 @@ int ZEXPORT gzputc(file, c)
gzFile file; gzFile file;
int c; int c;
{ {
unsigned have;
unsigned char buf[1]; unsigned char buf[1];
gz_statep state; gz_statep state;
z_streamp strm; z_streamp strm;
...@@ -267,10 +270,12 @@ int ZEXPORT gzputc(file, c) ...@@ -267,10 +270,12 @@ int ZEXPORT gzputc(file, c)
/* try writing to input buffer for speed (state->size == 0 if buffer not /* try writing to input buffer for speed (state->size == 0 if buffer not
initialized) */ initialized) */
if (strm->avail_in < state->size) { if (strm->avail_in == 0)
if (strm->avail_in == 0) strm->next_in = state->in;
strm->next_in = state->in; have = strm->next_in + strm->avail_in - state->in;
strm->next_in[strm->avail_in++] = c; if (have < state->size) {
state->in[have] = c;
strm->avail_in++;
state->x.pos++; state->x.pos++;
return c & 0xff; return c & 0xff;
} }
......
...@@ -255,7 +255,7 @@ out_func out; ...@@ -255,7 +255,7 @@ out_func out;
void FAR *out_desc; void FAR *out_desc;
{ {
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned char FAR *next; /* next input */ z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */ unsigned char FAR *put; /* next output */
unsigned have, left; /* available input and output */ unsigned have, left; /* available input and output */
unsigned long hold; /* bit buffer */ unsigned long hold; /* bit buffer */
......
...@@ -69,8 +69,8 @@ z_streamp strm; ...@@ -69,8 +69,8 @@ z_streamp strm;
unsigned start; /* inflate()'s starting value for strm->avail_out */ unsigned start; /* inflate()'s starting value for strm->avail_out */
{ {
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned char FAR *in; /* local strm->next_in */ z_const unsigned char FAR *in; /* local strm->next_in */
unsigned char FAR *last; /* while in < last, enough input available */ z_const unsigned char FAR *last; /* while in < last, enough input available */
unsigned char FAR *out; /* local strm->next_out */ unsigned char FAR *out; /* local strm->next_out */
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
unsigned char FAR *end; /* while out < end, enough space available */ unsigned char FAR *end; /* while out < end, enough space available */
......
...@@ -93,11 +93,12 @@ ...@@ -93,11 +93,12 @@
/* function prototypes */ /* function prototypes */
local void fixedtables OF((struct inflate_state FAR *state)); local void fixedtables OF((struct inflate_state FAR *state));
local int updatewindow OF((z_streamp strm, unsigned out)); local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
unsigned copy));
#ifdef BUILDFIXED #ifdef BUILDFIXED
void makefixed OF((void)); void makefixed OF((void));
#endif #endif
local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
unsigned len)); unsigned len));
int ZEXPORT inflateResetKeep(strm) int ZEXPORT inflateResetKeep(strm)
...@@ -375,12 +376,13 @@ void makefixed() ...@@ -375,12 +376,13 @@ void makefixed()
output will fall in the output data, making match copies simpler and faster. output will fall in the output data, making match copies simpler and faster.
The advantage may be dependent on the size of the processor's data caches. The advantage may be dependent on the size of the processor's data caches.
*/ */
local int updatewindow(strm, out) local int updatewindow(strm, end, copy)
z_streamp strm; z_streamp strm;
unsigned out; const Bytef *end;
unsigned copy;
{ {
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned copy, dist; unsigned dist;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
...@@ -400,19 +402,18 @@ unsigned out; ...@@ -400,19 +402,18 @@ unsigned out;
} }
/* copy state->wsize or less output bytes into the circular window */ /* copy state->wsize or less output bytes into the circular window */
copy = out - strm->avail_out;
if (copy >= state->wsize) { if (copy >= state->wsize) {
zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); zmemcpy(state->window, end - state->wsize, state->wsize);
state->wnext = 0; state->wnext = 0;
state->whave = state->wsize; state->whave = state->wsize;
} }
else { else {
dist = state->wsize - state->wnext; dist = state->wsize - state->wnext;
if (dist > copy) dist = copy; if (dist > copy) dist = copy;
zmemcpy(state->window + state->wnext, strm->next_out - copy, dist); zmemcpy(state->window + state->wnext, end - copy, dist);
copy -= dist; copy -= dist;
if (copy) { if (copy) {
zmemcpy(state->window, strm->next_out - copy, copy); zmemcpy(state->window, end - copy, copy);
state->wnext = copy; state->wnext = copy;
state->whave = state->wsize; state->whave = state->wsize;
} }
...@@ -606,7 +607,7 @@ z_streamp strm; ...@@ -606,7 +607,7 @@ z_streamp strm;
int flush; int flush;
{ {
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned char FAR *next; /* next input */ z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */ unsigned char FAR *put; /* next output */
unsigned have, left; /* available input and output */ unsigned have, left; /* available input and output */
unsigned long hold; /* bit buffer */ unsigned long hold; /* bit buffer */
...@@ -920,7 +921,7 @@ int flush; ...@@ -920,7 +921,7 @@ int flush;
while (state->have < 19) while (state->have < 19)
state->lens[order[state->have++]] = 0; state->lens[order[state->have++]] = 0;
state->next = state->codes; state->next = state->codes;
state->lencode = (code const FAR *)(state->next); state->lencode = (const code FAR *)(state->next);
state->lenbits = 7; state->lenbits = 7;
ret = inflate_table(CODES, state->lens, 19, &(state->next), ret = inflate_table(CODES, state->lens, 19, &(state->next),
&(state->lenbits), state->work); &(state->lenbits), state->work);
...@@ -994,7 +995,7 @@ int flush; ...@@ -994,7 +995,7 @@ int flush;
values here (9 and 6) without reading the comments in inftrees.h values here (9 and 6) without reading the comments in inftrees.h
concerning the ENOUGH constants, which depend on those values */ concerning the ENOUGH constants, which depend on those values */
state->next = state->codes; state->next = state->codes;
state->lencode = (code const FAR *)(state->next); state->lencode = (const code FAR *)(state->next);
state->lenbits = 9; state->lenbits = 9;
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
&(state->lenbits), state->work); &(state->lenbits), state->work);
...@@ -1003,7 +1004,7 @@ int flush; ...@@ -1003,7 +1004,7 @@ int flush;
state->mode = BAD; state->mode = BAD;
break; break;
} }
state->distcode = (code const FAR *)(state->next); state->distcode = (const code FAR *)(state->next);
state->distbits = 6; state->distbits = 6;
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
&(state->next), &(state->distbits), state->work); &(state->next), &(state->distbits), state->work);
...@@ -1230,7 +1231,7 @@ int flush; ...@@ -1230,7 +1231,7 @@ int flush;
RESTORE(); RESTORE();
if (state->wsize || (out != strm->avail_out && state->mode < BAD && if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
(state->mode < CHECK || flush != Z_FINISH))) (state->mode < CHECK || flush != Z_FINISH)))
if (updatewindow(strm, out)) { if (updatewindow(strm, strm->next_out, out - strm->avail_out)) {
state->mode = MEM; state->mode = MEM;
return Z_MEM_ERROR; return Z_MEM_ERROR;
} }
...@@ -1294,8 +1295,6 @@ uInt dictLength; ...@@ -1294,8 +1295,6 @@ uInt dictLength;
{ {
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned long dictid; unsigned long dictid;
unsigned char *next;
unsigned avail;
int ret; int ret;
/* check state */ /* check state */
...@@ -1314,13 +1313,7 @@ uInt dictLength; ...@@ -1314,13 +1313,7 @@ uInt dictLength;
/* copy dictionary to window using updatewindow(), which will amend the /* copy dictionary to window using updatewindow(), which will amend the
existing dictionary if appropriate */ existing dictionary if appropriate */
next = strm->next_out; ret = updatewindow(strm, dictionary + dictLength, dictLength);
avail = strm->avail_out;
strm->next_out = (Bytef *)dictionary + dictLength;
strm->avail_out = 0;
ret = updatewindow(strm, dictLength);
strm->avail_out = avail;
strm->next_out = next;
if (ret) { if (ret) {
state->mode = MEM; state->mode = MEM;
return Z_MEM_ERROR; return Z_MEM_ERROR;
...@@ -1360,7 +1353,7 @@ gz_headerp head; ...@@ -1360,7 +1353,7 @@ gz_headerp head;
*/ */
local unsigned syncsearch(have, buf, len) local unsigned syncsearch(have, buf, len)
unsigned FAR *have; unsigned FAR *have;
unsigned char FAR *buf; const unsigned char FAR *buf;
unsigned len; unsigned len;
{ {
unsigned got; unsigned got;
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
} \ } \
} }
const char hello[] = "hello, hello!"; z_const char hello[] = "hello, hello!";
/* "hello world" would be more standard, but the repeated "hello" /* "hello world" would be more standard, but the repeated "hello"
* stresses the compression code better, sorry... * stresses the compression code better, sorry...
*/ */
...@@ -212,7 +212,7 @@ void test_deflate(compr, comprLen) ...@@ -212,7 +212,7 @@ void test_deflate(compr, comprLen)
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
CHECK_ERR(err, "deflateInit"); CHECK_ERR(err, "deflateInit");
c_stream.next_in = (Bytef*)hello; c_stream.next_in = (z_const unsigned char *)hello;
c_stream.next_out = compr; c_stream.next_out = compr;
while (c_stream.total_in != len && c_stream.total_out < comprLen) { while (c_stream.total_in != len && c_stream.total_out < comprLen) {
...@@ -387,7 +387,7 @@ void test_flush(compr, comprLen) ...@@ -387,7 +387,7 @@ void test_flush(compr, comprLen)
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
CHECK_ERR(err, "deflateInit"); CHECK_ERR(err, "deflateInit");
c_stream.next_in = (Bytef*)hello; c_stream.next_in = (z_const unsigned char *)hello;
c_stream.next_out = compr; c_stream.next_out = compr;
c_stream.avail_in = 3; c_stream.avail_in = 3;
c_stream.avail_out = (uInt)*comprLen; c_stream.avail_out = (uInt)*comprLen;
...@@ -476,7 +476,7 @@ void test_dict_deflate(compr, comprLen) ...@@ -476,7 +476,7 @@ void test_dict_deflate(compr, comprLen)
c_stream.next_out = compr; c_stream.next_out = compr;
c_stream.avail_out = (uInt)comprLen; c_stream.avail_out = (uInt)comprLen;
c_stream.next_in = (Bytef*)hello; c_stream.next_in = (z_const unsigned char *)hello;
c_stream.avail_in = (uInt)strlen(hello)+1; c_stream.avail_in = (uInt)strlen(hello)+1;
err = deflate(&c_stream, Z_FINISH); err = deflate(&c_stream, Z_FINISH);
......
...@@ -146,8 +146,8 @@ local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); ...@@ -146,8 +146,8 @@ local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
local int build_bl_tree OF((deflate_state *s)); local int build_bl_tree OF((deflate_state *s));
local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
int blcodes)); int blcodes));
local void compress_block OF((deflate_state *s, ct_data *ltree, local void compress_block OF((deflate_state *s, const ct_data *ltree,
ct_data *dtree)); const ct_data *dtree));
local int detect_data_type OF((deflate_state *s)); local int detect_data_type OF((deflate_state *s));
local unsigned bi_reverse OF((unsigned value, int length)); local unsigned bi_reverse OF((unsigned value, int length));
local void bi_windup OF((deflate_state *s)); local void bi_windup OF((deflate_state *s));
...@@ -972,7 +972,8 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) ...@@ -972,7 +972,8 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
} else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
#endif #endif
send_bits(s, (STATIC_TREES<<1)+last, 3); send_bits(s, (STATIC_TREES<<1)+last, 3);
compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); compress_block(s, (const ct_data *)static_ltree,
(const ct_data *)static_dtree);
#ifdef DEBUG #ifdef DEBUG
s->compressed_len += 3 + s->static_len; s->compressed_len += 3 + s->static_len;
#endif #endif
...@@ -980,7 +981,8 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) ...@@ -980,7 +981,8 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
send_bits(s, (DYN_TREES<<1)+last, 3); send_bits(s, (DYN_TREES<<1)+last, 3);
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
max_blindex+1); max_blindex+1);
compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); compress_block(s, (const ct_data *)s->dyn_ltree,
(const ct_data *)s->dyn_dtree);
#ifdef DEBUG #ifdef DEBUG
s->compressed_len += 3 + s->opt_len; s->compressed_len += 3 + s->opt_len;
#endif #endif
...@@ -1057,8 +1059,8 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc) ...@@ -1057,8 +1059,8 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
*/ */
local void compress_block(s, ltree, dtree) local void compress_block(s, ltree, dtree)
deflate_state *s; deflate_state *s;
ct_data *ltree; /* literal tree */ const ct_data *ltree; /* literal tree */
ct_data *dtree; /* distance tree */ const ct_data *dtree; /* distance tree */
{ {
unsigned dist; /* distance of matched string */ unsigned dist; /* distance of matched string */
int lc; /* match length or unmatched char (if dist == 0) */ int lc; /* match length or unmatched char (if dist == 0) */
......
...@@ -30,7 +30,7 @@ int ZEXPORT uncompress (dest, destLen, source, sourceLen) ...@@ -30,7 +30,7 @@ int ZEXPORT uncompress (dest, destLen, source, sourceLen)
z_stream stream; z_stream stream;
int err; int err;
stream.next_in = (Bytef*)source; stream.next_in = (z_const Bytef *)source;
stream.avail_in = (uInt)sourceLen; stream.avail_in = (uInt)sourceLen;
/* Check for source > 64K on 16-bit machine: */ /* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
......
...@@ -1022,7 +1022,8 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, ...@@ -1022,7 +1022,8 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
the version of the header file. the version of the header file.
*/ */
typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); typedef unsigned (*in_func) OF((void FAR *,
z_const unsigned char FAR * FAR *));
typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
struct internal_state {int dummy;}; /* for buggy compilers */ struct internal_state {int dummy;}; /* for buggy compilers */
#endif #endif
const char * const z_errmsg[10] = { z_const char * const z_errmsg[10] = {
"need dictionary", /* Z_NEED_DICT 2 */ "need dictionary", /* Z_NEED_DICT 2 */
"stream end", /* Z_STREAM_END 1 */ "stream end", /* Z_STREAM_END 1 */
"", /* Z_OK 0 */ "", /* Z_OK 0 */
......
...@@ -44,13 +44,13 @@ typedef unsigned short ush; ...@@ -44,13 +44,13 @@ typedef unsigned short ush;
typedef ush FAR ushf; typedef ush FAR ushf;
typedef unsigned long ulg; typedef unsigned long ulg;
extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* (size given to avoid silly warnings with Visual C++) */ /* (size given to avoid silly warnings with Visual C++) */
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
#define ERR_RETURN(strm,err) \ #define ERR_RETURN(strm,err) \
return (strm->msg = (char*)ERR_MSG(err), (err)) return (strm->msg = ERR_MSG(err), (err))
/* To be used only when the state is known to be valid */ /* To be used only when the state is known to be valid */
/* common constants */ /* common constants */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册