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>
This commit is contained in:
parent
6d60c4d468
commit
2943ac5381
|
@ -42,6 +42,7 @@
|
|||
#include "packet-ssl.h"
|
||||
|
||||
#ifdef HAVE_LIBZ
|
||||
#define ZLIB_CONST
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
|
@ -961,7 +962,13 @@ static guint8* spdy_decompress_header_block(tvbuff_t *tvb,
|
|||
const guint8 *hptr = tvb_get_ptr(tvb, offset, length);
|
||||
guint8 *uncomp_block = (guint8 *)wmem_alloc(wmem_packet_scope(), DECOMPRESS_BUFSIZE);
|
||||
|
||||
#ifdef z_const
|
||||
decomp->next_in = (z_const Bytef *)hptr;
|
||||
#else
|
||||
DIAG_OFF(cast-qual)
|
||||
decomp->next_in = (Bytef *)hptr;
|
||||
DIAG_ON(cast-qual)
|
||||
#endif
|
||||
decomp->avail_in = length;
|
||||
decomp->next_out = uncomp_block;
|
||||
decomp->avail_out = DECOMPRESS_BUFSIZE;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_LIBZ
|
||||
#define ZLIB_CONST
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -27,10 +27,6 @@
|
|||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBZ
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
#include "wtap-int.h"
|
||||
|
||||
#include "file_wrappers.h"
|
||||
|
|
Loading…
Reference in New Issue