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 /gzlib.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 'gzlib.c')
-rw-r--r-- | gzlib.c | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -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) |