diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2012-08-12 18:08:52 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2012-08-13 00:02:40 -0700 |
commit | 62d6112a7981ad7c34f3b43cffdf00d4662a4f25 (patch) | |
tree | aed93070f7e1be31868dce1d62a1de6ffc1360f9 /inflate.c | |
parent | fb4e0599a5ddaef9eee726f786b9edef4943432b (diff) | |
download | zlib-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.
Diffstat (limited to 'inflate.c')
-rw-r--r-- | inflate.c | 41 |
1 files changed, 17 insertions, 24 deletions
@@ -93,11 +93,12 @@ | |||
93 | 93 | ||
94 | /* function prototypes */ | 94 | /* function prototypes */ |
95 | local void fixedtables OF((struct inflate_state FAR *state)); | 95 | local void fixedtables OF((struct inflate_state FAR *state)); |
96 | local int updatewindow OF((z_streamp strm, unsigned out)); | 96 | local 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 |
100 | local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, | 101 | local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, |
101 | unsigned len)); | 102 | unsigned len)); |
102 | 103 | ||
103 | int ZEXPORT inflateResetKeep(strm) | 104 | int 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 | */ |
378 | local int updatewindow(strm, out) | 379 | local int updatewindow(strm, end, copy) |
379 | z_streamp strm; | 380 | z_streamp strm; |
380 | unsigned out; | 381 | const Bytef *end; |
382 | unsigned 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; | |||
606 | int flush; | 607 | int 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 | */ |
1361 | local unsigned syncsearch(have, buf, len) | 1354 | local unsigned syncsearch(have, buf, len) |
1362 | unsigned FAR *have; | 1355 | unsigned FAR *have; |
1363 | unsigned char FAR *buf; | 1356 | const unsigned char FAR *buf; |
1364 | unsigned len; | 1357 | unsigned len; |
1365 | { | 1358 | { |
1366 | unsigned got; | 1359 | unsigned got; |