From 857e4f1e0481d87ac92b258804a00c501c75ceb4 Mon Sep 17 00:00:00 2001 From: Nathan Moinvaziri Date: Sun, 13 Jun 2021 15:16:20 -0700 Subject: [PATCH] Added Z_UNUSED define for ignore unused variables. --- deflate.h | 4 ++-- inflate.c | 2 +- test/example.c | 2 +- test/fuzz/checksum_fuzzer.c | 16 ++++++++-------- test/fuzz/standalone_fuzz_target_runner.c | 4 +++- test/infcover.c | 10 +++++----- trees_emit.h | 2 +- zbuild.h | 2 ++ zutil.c | 4 ++-- 9 files changed, 25 insertions(+), 21 deletions(-) diff --git a/deflate.h b/deflate.h index cf7d4906..16e63c75 100644 --- a/deflate.h +++ b/deflate.h @@ -402,9 +402,9 @@ void Z_INTERNAL flush_pending(PREFIX3(streamp) strm); # define sent_bits_add(s, bits) s->bits_sent += (bits) # define sent_bits_align(s) s->bits_sent = (s->bits_sent + 7) & ~7L #else -# define cmpr_bits_add(s, len) (void)(len) +# define cmpr_bits_add(s, len) Z_UNUSED(len) # define cmpr_bits_align(s) -# define sent_bits_add(s, bits) (void)(bits) +# define sent_bits_add(s, bits) Z_UNUSED(bits) # define sent_bits_align(s) #endif diff --git a/inflate.c b/inflate.c index e2a6f2c6..6ba6e83d 100644 --- a/inflate.c +++ b/inflate.c @@ -1283,7 +1283,7 @@ int32_t Z_EXPORT PREFIX(inflateUndermine)(PREFIX3(stream) *strm, int32_t subvert state->sane = !subvert; return Z_OK; #else - (void)subvert; + Z_UNUSED(subvert); state->sane = 1; return Z_DATA_ERROR; #endif diff --git a/test/example.c b/test/example.c index 8a8905dd..339ea8cd 100644 --- a/test/example.c +++ b/test/example.c @@ -229,7 +229,7 @@ void test_gzio(const char *fname, unsigned char *uncompr, z_size_t uncomprLen) { fprintf(stderr, "gzclose unexpected return when handle null\n"); exit(1); } - (void)read; + Z_UNUSED(read); #endif } diff --git a/test/fuzz/checksum_fuzzer.c b/test/fuzz/checksum_fuzzer.c index ef994211..da9f1305 100644 --- a/test/fuzz/checksum_fuzzer.c +++ b/test/fuzz/checksum_fuzzer.c @@ -42,16 +42,16 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataLen) { uint32_t crc4 = PREFIX(crc32_combine_op)(crc1, crc3, op); crc1 = PREFIX(crc32_z)(crc1, data + offset, buffSize); assert(crc1 == crc4); - (void)crc1; - (void)crc4; + Z_UNUSED(crc1); + Z_UNUSED(crc4); } crc1 = PREFIX(crc32_z)(crc1, data + offset, dataLen % buffSize); crc2 = PREFIX(crc32_z)(crc2, data, dataLen); assert(crc1 == crc2); - (void)crc1; - (void)crc2; + Z_UNUSED(crc1); + Z_UNUSED(crc2); combine1 = PREFIX(crc32_combine)(crc1, crc2, (z_off_t)dataLen); combine2 = PREFIX(crc32_combine)(crc1, crc1, (z_off_t)dataLen); assert(combine1 == combine2); @@ -73,13 +73,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataLen) { adler2 = PREFIX(adler32_z)(adler2, data, dataLen); assert(adler1 == adler2); - (void)adler1; - (void)adler2; + Z_UNUSED(adler1); + Z_UNUSED(adler2); combine1 = PREFIX(adler32_combine)(adler1, adler2, (z_off_t)dataLen); combine2 = PREFIX(adler32_combine)(adler1, adler1, (z_off_t)dataLen); assert(combine1 == combine2); - (void)combine1; - (void)combine2; + Z_UNUSED(combine1); + Z_UNUSED(combine2); /* This function must return 0. */ return 0; diff --git a/test/fuzz/standalone_fuzz_target_runner.c b/test/fuzz/standalone_fuzz_target_runner.c index a291b488..49f5e7fa 100644 --- a/test/fuzz/standalone_fuzz_target_runner.c +++ b/test/fuzz/standalone_fuzz_target_runner.c @@ -2,6 +2,8 @@ #include #include +#include "zbuild.h" + extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size); int main(int argc, char **argv) { @@ -28,7 +30,7 @@ int main(int argc, char **argv) { free(buf); err = fclose(f); assert(err == 0); - (void)err; + Z_UNUSED(err); fprintf(stderr, "Done: %s: (%d bytes)\n", argv[i], (int)n_read); } diff --git a/test/infcover.c b/test/infcover.c index 3466b202..3446289e 100644 --- a/test/infcover.c +++ b/test/infcover.c @@ -348,7 +348,7 @@ static void inf(char *hex, char *what, unsigned step, int win, unsigned len, int ret = PREFIX(inflateReset2)(&strm, -8); assert(ret == Z_OK); ret = PREFIX(inflateEnd)(&strm); assert(ret == Z_OK); mem_done(&strm, what); - (void)err; + Z_UNUSED(err); } /* cover all of the lines in inflate.c up to inflate() */ @@ -386,7 +386,7 @@ static void cover_support(void) { ret = PREFIX(inflateInit)(&strm); assert(ret == Z_OK); ret = PREFIX(inflateEnd)(&strm); assert(ret == Z_OK); fputs("inflate built-in memory routines\n", stderr); - (void)ret; + Z_UNUSED(ret); } /* cover all inflate() header and trailer cases and code after inflate() */ @@ -470,7 +470,7 @@ static unsigned pull(void *desc, z_const unsigned char **buf) { static int push(void *desc, unsigned char *buf, unsigned len) { buf += len; - (void)buf; + Z_UNUSED(buf); return desc != NULL; /* force error if desc not null */ } @@ -511,7 +511,7 @@ static void cover_back(void) { assert(ret == Z_OK); ret = PREFIX(inflateBackEnd)(&strm); assert(ret == Z_OK); fputs("inflateBack built-in memory routines\n", stderr); - (void)ret; + Z_UNUSED(ret); } /* do a raw inflate of data in hexadecimal with both inflate and inflateBack */ @@ -647,7 +647,7 @@ static void cover_trees(void) { ret = zng_inflate_table(DISTS, lens, 16, &next, &bits, work); assert(ret == 1); fputs("inflate_table not enough errors\n", stderr); - (void)ret; + Z_UNUSED(ret); } /* cover remaining inffast.c decoding and window copying */ diff --git a/trees_emit.h b/trees_emit.h index 454488ed..52af7a40 100644 --- a/trees_emit.h +++ b/trees_emit.h @@ -175,7 +175,7 @@ static inline void zng_emit_end_block(deflate_state *s, const ct_data *ltree, co s->bi_buf = bi_buf; Tracev((stderr, "\n+++ Emit End Block: Last: %u Pending: %u Total Out: %" PRIu64 "\n", last, s->pending, (uint64_t)s->strm->total_out)); - (void)last; + Z_UNUSED(last); } /* =========================================================================== diff --git a/zbuild.h b/zbuild.h index 87b7426a..3c5e5fb4 100644 --- a/zbuild.h +++ b/zbuild.h @@ -30,5 +30,7 @@ #define MIN(a, b) ((a) > (b) ? (b) : (a)) /* Maximum of a and b. */ #define MAX(a, b) ((a) < (b) ? (b) : (a)) +/* Ignore unused variable warning */ +#define Z_UNUSED(var) (void)(var) #endif diff --git a/zutil.c b/zutil.c index 74d75243..53e43b0d 100644 --- a/zutil.c +++ b/zutil.c @@ -101,11 +101,11 @@ const char * Z_EXPORT PREFIX(zError)(int err) { } void Z_INTERNAL *zng_calloc(void *opaque, unsigned items, unsigned size) { - (void)opaque; + Z_UNUSED(opaque); return zng_alloc((size_t)items * (size_t)size); } void Z_INTERNAL zng_cfree(void *opaque, void *ptr) { - (void)opaque; + Z_UNUSED(opaque); zng_free(ptr); } -- 2.47.3