diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-12-16 01:37:00 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2015-12-16 17:58:09 +0000 |
commit | 2943ac5381ed424348c66db76cd6869dbdf71710 (patch) | |
tree | 527f5d273cdad18b69de94b743e67c98204aaa94 /wiretap | |
parent | 6d60c4d4684c2c03a43f1b8720497348cf17d357 (diff) |
Make zlib API constness-aware, take 2.
ZLIB_CONST must be defined before including zlib.h to expose z_const,
*AND* z_const shouldn't be used unless it's defined, because older
versions of zlib don't define it even if you define ZLIB_CONST.
While we're at it, throw in some DIAG_OFF(cast-qual)/DIAG_ON(cast-qual)
pairs to suppress unavoidable "cast throws away const qualification"
warnings.
The original "make zlib constness-aware" change also removed an
unnecessary include of <zlib.h> from wiretap/wtap.c, so we do that as
well.
Change-Id: I3c5269a8fbc54bbbb4d316544cc7b8fa30614c19
Reviewed-on: https://code.wireshark.org/review/12675
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap')
-rw-r--r-- | wiretap/file_wrappers.c | 18 | ||||
-rw-r--r-- | wiretap/wtap.c | 4 |
2 files changed, 17 insertions, 5 deletions
diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c index 5918a55f6f..0edd8945bb 100644 --- a/wiretap/file_wrappers.c +++ b/wiretap/file_wrappers.c @@ -45,9 +45,11 @@ #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" +#include <wsutil/ws_diag_control.h> #include <wsutil/file_util.h> #ifdef HAVE_LIBZ +#define ZLIB_CONST #include <zlib.h> #endif /* HAVE_LIBZ */ @@ -473,7 +475,13 @@ zlib_read(FILE_T state, unsigned char *buf, unsigned int count) ret = inflate(strm, Z_NO_FLUSH); #endif state->avail_in = strm->avail_in; +#ifdef z_const +DIAG_OFF(cast-qual) + state->next_in = (unsigned char *)strm->next_in; +DIAG_ON(cast-qual) +#else state->next_in = strm->next_in; +#endif if (ret == Z_STREAM_ERROR) { state->err = WTAP_ERR_DECOMPRESS; state->err_info = strm->msg; @@ -1672,7 +1680,13 @@ gzwfile_write(GZWFILE_T state, const void *buf, guint len) n = state->size - strm->avail_in; if (n > len) n = len; +#ifdef z_const +DIAG_OFF(cast-qual) + memcpy((Bytef *)strm->next_in + strm->avail_in, buf, n); +DIAG_ON(cast-qual) +#else memcpy(strm->next_in + strm->avail_in, buf, n); +#endif strm->avail_in += n; state->pos += n; buf = (const char *)buf + n; @@ -1688,10 +1702,12 @@ gzwfile_write(GZWFILE_T state, const void *buf, guint len) /* directly compress user buffer to file */ strm->avail_in = len; -#if ZLIB_CONST +#ifdef z_const strm->next_in = (z_const Bytef *)buf; #else +DIAG_OFF(cast-qual) strm->next_in = (Bytef *)buf; +DIAG_ON(cast-qual) #endif state->pos += len; if (gz_comp(state, Z_NO_FLUSH) == -1) diff --git a/wiretap/wtap.c b/wiretap/wtap.c index 30b66cd46f..c4c35e8a74 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -27,10 +27,6 @@ #include <sys/types.h> #endif -#ifdef HAVE_LIBZ -#include <zlib.h> -#endif - #include "wtap-int.h" #include "file_wrappers.h" |