From 62d6112a7981ad7c34f3b43cffdf00d4662a4f25 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Sun, 12 Aug 2012 18:08:52 -0700 Subject: 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. --- gzlib.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'gzlib.c') 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) /* return error information */ if (errnum != NULL) *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 -- */ @@ -592,16 +593,13 @@ void ZLIB_INTERNAL gz_error(state, err, msg) if (msg == NULL) return; - /* for an out of memory error, save as static string */ - if (err == Z_MEM_ERROR) { - state->msg = (char *)msg; + /* for an out of memory error, return literal string when requested */ + if (err == Z_MEM_ERROR) return; - } /* construct error message with path */ if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { state->err = Z_MEM_ERROR; - state->msg = (char *)"out of memory"; return; } #if !defined(NO_snprintf) && !defined(NO_vsnprintf) -- cgit v1.2.3-55-g6feb