From e0a711cdde1d0390a922f80b69e3b365533b34cf Mon Sep 17 00:00:00 2001 From: Nathan Moinvaziri Date: Tue, 7 Jan 2020 19:09:34 -0800 Subject: [PATCH] Fixed formatting, 4 spaces for code intent, 2 spaces for preprocessor indent, initial function brace on the same line as definition, removed extraneous spaces and new lines. --- arch/arm/armfeature.c | 37 +++++------ arch/arm/insert_string_acle.c | 4 +- arch/s390/dfltcc_common.c | 18 ++--- arch/s390/dfltcc_deflate.c | 36 ++++------ arch/s390/dfltcc_detail.h | 12 ++-- arch/s390/dfltcc_inflate.c | 15 ++--- arch/x86/crc_folding.c | 2 +- arch/x86/deflate_quick.c | 30 ++++----- arch/x86/fill_window_sse.c | 4 +- arch/x86/insert_string_sse.c | 4 +- arch/x86/x86.h | 8 +-- cmake/archdetect.cmake | 1 - compress.c | 4 +- crc32.c | 17 ++--- deflate.c | 106 +++++++++++++++-------------- deflate.h | 46 +++++++------ deflate_medium.c | 6 +- deflate_p.h | 10 +-- fallback_builtins.h | 5 +- functable.c | 77 +++++++++++---------- gzguts.h | 8 +-- gzread.c | 48 +++++++------- infback.c | 2 +- inffast.c | 6 +- inflate.c | 3 +- inftrees.c | 2 +- match_p.h | 20 +++--- memcopy.h | 104 ++++++++++++++--------------- test/example.c | 54 +++++---------- test/fuzz/checksum_fuzzer.c | 114 ++++++++++++++++---------------- test/fuzz/example_dict_fuzzer.c | 5 +- test/fuzz/minigzip_fuzzer.c | 28 +++----- test/infcover.c | 57 ++++++---------- test/minigzip.c | 55 +++++++-------- test/switchlevels.c | 12 ++-- tools/maketrees.c | 2 +- trees.c | 4 +- trees.h | 2 +- uncompr.c | 10 ++- zendian.h | 78 +++++++++++----------- zlib-ng.h | 6 +- zlib.h | 2 +- zutil.c | 28 +++----- zutil.h | 90 ++++++++++++------------- 44 files changed, 543 insertions(+), 639 deletions(-) diff --git a/arch/arm/armfeature.c b/arch/arm/armfeature.c index 7c4758b6ee..9ad9eed638 100644 --- a/arch/arm/armfeature.c +++ b/arch/arm/armfeature.c @@ -1,39 +1,38 @@ #include "../../zutil.h" #if defined(__linux__) -# include -# include +# include +# include #elif defined(_WIN32) -# include +# include #endif static int arm_has_crc32() { #if defined(__linux__) && defined(HWCAP2_CRC32) - return (getauxval(AT_HWCAP2) & HWCAP2_CRC32) != 0 ? 1 : 0; + return (getauxval(AT_HWCAP2) & HWCAP2_CRC32) != 0 ? 1 : 0; #elif defined(ARM_NOCHECK_ACLE) - return 1; + return 1; #else - return 0; + return 0; #endif } /* AArch64 has neon. */ #if !defined(__aarch64__) && !defined(_M_ARM64) -static inline int arm_has_neon() -{ - #if defined(__linux__) && defined(HWCAP_NEON) +static inline int arm_has_neon() { +#if defined(__linux__) && defined(HWCAP_NEON) return (getauxval(AT_HWCAP) & HWCAP_NEON) != 0 ? 1 : 0; - #elif defined(_M_ARM) && defined(WINAPI_FAMILY_PARTITION) - #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) +#elif defined(_M_ARM) && defined(WINAPI_FAMILY_PARTITION) +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) return 1; /* Always supported */ - #endif - #endif +# endif +#endif - #if defined(ARM_NOCHECK_NEON) +#if defined(ARM_NOCHECK_NEON) return 1; - #else +#else return 0; - #endif +#endif } #endif @@ -42,9 +41,9 @@ ZLIB_INTERNAL int arm_cpu_has_crc32; void ZLIB_INTERNAL arm_check_features(void) { #if defined(__aarch64__) || defined(_M_ARM64) - arm_cpu_has_neon = 1; /* always available */ + arm_cpu_has_neon = 1; /* always available */ #else - arm_cpu_has_neon = arm_has_neon(); + arm_cpu_has_neon = arm_has_neon(); #endif - arm_cpu_has_crc32 = arm_has_crc32(); + arm_cpu_has_crc32 = arm_has_crc32(); } diff --git a/arch/arm/insert_string_acle.c b/arch/arm/insert_string_acle.c index 363f050b04..b6ddc070e6 100644 --- a/arch/arm/insert_string_acle.c +++ b/arch/arm/insert_string_acle.c @@ -43,9 +43,9 @@ Pos insert_string_acle(deflate_state *const s, const Pos str, unsigned int count s->prev[p & s->w_mask] = head; s->head[hm] = p; if (p == lp) - ret = head; + ret = head; } else if (p == lp) { - ret = p; + ret = p; } } return ret; diff --git a/arch/s390/dfltcc_common.c b/arch/s390/dfltcc_common.c index c662f1de2d..364825e332 100644 --- a/arch/s390/dfltcc_common.c +++ b/arch/s390/dfltcc_common.c @@ -12,8 +12,7 @@ `posix_memalign' is not an option. Thus, we overallocate and take the aligned portion of the buffer. */ -static inline int is_dfltcc_enabled(void) -{ +static inline int is_dfltcc_enabled(void) { uint64_t facilities[(DFLTCC_FACILITY / 64) + 1]; register uint8_t r0 __asm__("r0"); @@ -31,8 +30,7 @@ static inline int is_dfltcc_enabled(void) return is_bit_set((const char *)facilities, DFLTCC_FACILITY); } -void ZLIB_INTERNAL dfltcc_reset(PREFIX3(streamp) strm, uInt size) -{ +void ZLIB_INTERNAL dfltcc_reset(PREFIX3(streamp) strm, uInt size) { struct dfltcc_state *dfltcc_state = (struct dfltcc_state *)((char *)strm->state + ALIGN_UP(size, 8)); struct dfltcc_qaf_param *param = (struct dfltcc_qaf_param *)&dfltcc_state->param; @@ -55,20 +53,17 @@ void ZLIB_INTERNAL dfltcc_reset(PREFIX3(streamp) strm, uInt size) dfltcc_state->param.ribm = DFLTCC_RIBM; } -void ZLIB_INTERNAL *dfltcc_alloc_state(PREFIX3(streamp) strm, uInt items, uInt size) -{ +void ZLIB_INTERNAL *dfltcc_alloc_state(PREFIX3(streamp) strm, uInt items, uInt size) { return ZALLOC(strm, ALIGN_UP(items * size, 8) + sizeof(struct dfltcc_state), sizeof(unsigned char)); } -void ZLIB_INTERNAL dfltcc_copy_state(void *dst, const void *src, uInt size) -{ +void ZLIB_INTERNAL dfltcc_copy_state(void *dst, const void *src, uInt size) { memcpy(dst, src, ALIGN_UP(size, 8) + sizeof(struct dfltcc_state)); } static const int PAGE_ALIGN = 0x1000; -void ZLIB_INTERNAL *dfltcc_alloc_window(PREFIX3(streamp) strm, uInt items, uInt size) -{ +void ZLIB_INTERNAL *dfltcc_alloc_window(PREFIX3(streamp) strm, uInt items, uInt size) { void *p; void *w; @@ -83,8 +78,7 @@ void ZLIB_INTERNAL *dfltcc_alloc_window(PREFIX3(streamp) strm, uInt items, uInt return w; } -void ZLIB_INTERNAL dfltcc_free_window(PREFIX3(streamp) strm, void *w) -{ +void ZLIB_INTERNAL dfltcc_free_window(PREFIX3(streamp) strm, void *w) { if (w) ZFREE(strm, *(void **)((unsigned char *)w - sizeof(void *))); } diff --git a/arch/s390/dfltcc_deflate.c b/arch/s390/dfltcc_deflate.c index 454a0bb3ab..27fc8e3945 100644 --- a/arch/s390/dfltcc_deflate.c +++ b/arch/s390/dfltcc_deflate.c @@ -20,8 +20,7 @@ #include "dfltcc_detail.h" static inline int dfltcc_are_params_ok(int level, uInt window_bits, int strategy, uint16_t level_mask, - int reproducible) -{ + int reproducible) { return (level_mask & ((uint16_t)1 << level)) != 0 && (window_bits == HB_BITS) && (strategy == Z_FIXED || strategy == Z_DEFAULT_STRATEGY) && @@ -29,8 +28,7 @@ static inline int dfltcc_are_params_ok(int level, uInt window_bits, int strategy } -int ZLIB_INTERNAL dfltcc_can_deflate(PREFIX3(streamp) strm) -{ +int ZLIB_INTERNAL dfltcc_can_deflate(PREFIX3(streamp) strm) { deflate_state *state = (deflate_state *)strm->state; struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); @@ -48,8 +46,7 @@ int ZLIB_INTERNAL dfltcc_can_deflate(PREFIX3(streamp) strm) return 1; } -static inline void dfltcc_gdht(PREFIX3(streamp) strm) -{ +static inline void dfltcc_gdht(PREFIX3(streamp) strm) { deflate_state *state = (deflate_state *)strm->state; struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param; size_t avail_in = strm->avail_in; @@ -57,8 +54,7 @@ static inline void dfltcc_gdht(PREFIX3(streamp) strm) dfltcc(DFLTCC_GDHT, param, NULL, NULL, &strm->next_in, &avail_in, NULL); } -static inline dfltcc_cc dfltcc_cmpr(PREFIX3(streamp) strm) -{ +static inline dfltcc_cc dfltcc_cmpr(PREFIX3(streamp) strm) { deflate_state *state = (deflate_state *)strm->state; struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param; size_t avail_in = strm->avail_in; @@ -75,8 +71,7 @@ static inline dfltcc_cc dfltcc_cmpr(PREFIX3(streamp) strm) return cc; } -static inline void send_eobs(PREFIX3(streamp) strm, const struct dfltcc_param_v0 *param) -{ +static inline void send_eobs(PREFIX3(streamp) strm, const struct dfltcc_param_v0 *param) { deflate_state *state = (deflate_state *)strm->state; send_bits(state, bi_reverse(param->eobs >> (15 - param->eobl), param->eobl), param->eobl, state->bi_buf, state->bi_valid); @@ -96,8 +91,7 @@ static inline void send_eobs(PREFIX3(streamp) strm, const struct dfltcc_param_v0 #endif } -int ZLIB_INTERNAL dfltcc_deflate(PREFIX3(streamp) strm, int flush, block_state *result) -{ +int ZLIB_INTERNAL dfltcc_deflate(PREFIX3(streamp) strm, int flush, block_state *result) { deflate_state *state = (deflate_state *)strm->state; struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); struct dfltcc_param_v0 *param = &dfltcc_state->param; @@ -280,16 +274,14 @@ int ZLIB_INTERNAL dfltcc_deflate(PREFIX3(streamp) strm, int flush, block_state * fly with deflateParams, we need to convert between hardware and software window formats. */ -static int dfltcc_was_deflate_used(PREFIX3(streamp) strm) -{ +static int dfltcc_was_deflate_used(PREFIX3(streamp) strm) { deflate_state *state = (deflate_state *)strm->state; struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param; return strm->total_in > 0 || param->nt == 0 || param->hl > 0; } -int ZLIB_INTERNAL dfltcc_deflate_params(PREFIX3(streamp) strm, int level, int strategy) -{ +int ZLIB_INTERNAL dfltcc_deflate_params(PREFIX3(streamp) strm, int level, int strategy) { deflate_state *state = (deflate_state *)strm->state; struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); int could_deflate = dfltcc_can_deflate(strm); @@ -308,8 +300,7 @@ int ZLIB_INTERNAL dfltcc_deflate_params(PREFIX3(streamp) strm, int level, int st return Z_STREAM_ERROR; } -int ZLIB_INTERNAL dfltcc_can_set_reproducible(PREFIX3(streamp) strm, int reproducible) -{ +int ZLIB_INTERNAL dfltcc_can_set_reproducible(PREFIX3(streamp) strm, int reproducible) { deflate_state *state = (deflate_state *)strm->state; return reproducible != state->reproducible && !dfltcc_was_deflate_used(strm); @@ -318,8 +309,7 @@ int ZLIB_INTERNAL dfltcc_can_set_reproducible(PREFIX3(streamp) strm, int reprodu /* Preloading history. */ -static void append_history(struct dfltcc_param_v0 *param, unsigned char *history, const unsigned char *buf, uInt count) -{ +static void append_history(struct dfltcc_param_v0 *param, unsigned char *history, const unsigned char *buf, uInt count) { size_t offset; size_t n; @@ -350,8 +340,7 @@ static void append_history(struct dfltcc_param_v0 *param, unsigned char *history } int ZLIB_INTERNAL dfltcc_deflate_set_dictionary(PREFIX3(streamp) strm, - const unsigned char *dictionary, uInt dict_length) -{ + const unsigned char *dictionary, uInt dict_length) { deflate_state *state = (deflate_state *)strm->state; struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); struct dfltcc_param_v0 *param = &dfltcc_state->param; @@ -361,8 +350,7 @@ int ZLIB_INTERNAL dfltcc_deflate_set_dictionary(PREFIX3(streamp) strm, return Z_OK; } -int ZLIB_INTERNAL dfltcc_deflate_get_dictionary(PREFIX3(streamp) strm, unsigned char *dictionary, uInt *dict_length) -{ +int ZLIB_INTERNAL dfltcc_deflate_get_dictionary(PREFIX3(streamp) strm, unsigned char *dictionary, uInt *dict_length) { deflate_state *state = (deflate_state *)strm->state; struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); struct dfltcc_param_v0 *param = &dfltcc_state->param; diff --git a/arch/s390/dfltcc_detail.h b/arch/s390/dfltcc_detail.h index 513aa954fa..7c5c094510 100644 --- a/arch/s390/dfltcc_detail.h +++ b/arch/s390/dfltcc_detail.h @@ -46,8 +46,7 @@ typedef enum { #define DFLTCC_FACILITY 151 static inline dfltcc_cc dfltcc(int fn, void *param, - unsigned char **op1, size_t *len1, const unsigned char **op2, size_t *len2, void *hist) -{ + unsigned char **op1, size_t *len1, const unsigned char **op2, size_t *len2, void *hist) { unsigned char *t2 = op1 ? *op1 : NULL; size_t t3 = len1 ? *len1 : 0; const unsigned char *t4 = op2 ? *op2 : NULL; @@ -108,13 +107,11 @@ struct dfltcc_qaf_param { static_assert(sizeof(struct dfltcc_qaf_param) == 32, sizeof_struct_dfltcc_qaf_param_is_32); -static inline int is_bit_set(const char *bits, int n) -{ +static inline int is_bit_set(const char *bits, int n) { return bits[n / 8] & (1 << (7 - (n % 8))); } -static inline void clear_bit(char *bits, int n) -{ +static inline void clear_bit(char *bits, int n) { bits[n / 8] &= ~(1 << (7 - (n % 8))); } @@ -175,8 +172,7 @@ struct dfltcc_param_v0 { static_assert(sizeof(struct dfltcc_param_v0) == 1536, sizeof_struct_dfltcc_param_v0_is_1536); -static inline const char *oesc_msg(char *buf, int oesc) -{ +static inline const char *oesc_msg(char *buf, int oesc) { if (oesc == 0x00) return NULL; /* Successful completion */ else { diff --git a/arch/s390/dfltcc_inflate.c b/arch/s390/dfltcc_inflate.c index 4bd73719ee..ad17fe88bf 100644 --- a/arch/s390/dfltcc_inflate.c +++ b/arch/s390/dfltcc_inflate.c @@ -20,8 +20,7 @@ #include "dfltcc_inflate.h" #include "dfltcc_detail.h" -int ZLIB_INTERNAL dfltcc_can_inflate(PREFIX3(streamp) strm) -{ +int ZLIB_INTERNAL dfltcc_can_inflate(PREFIX3(streamp) strm) { struct inflate_state *state = (struct inflate_state *)strm->state; struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); @@ -33,8 +32,7 @@ int ZLIB_INTERNAL dfltcc_can_inflate(PREFIX3(streamp) strm) return is_bit_set(dfltcc_state->af.fns, DFLTCC_XPND) && is_bit_set(dfltcc_state->af.fmts, DFLTCC_FMT0); } -static inline dfltcc_cc dfltcc_xpnd(PREFIX3(streamp) strm) -{ +static inline dfltcc_cc dfltcc_xpnd(PREFIX3(streamp) strm) { struct inflate_state *state = (struct inflate_state *)strm->state; struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param; size_t avail_in = strm->avail_in; @@ -49,8 +47,7 @@ static inline dfltcc_cc dfltcc_xpnd(PREFIX3(streamp) strm) return cc; } -dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(PREFIX3(streamp) strm, int flush, int *ret) -{ +dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(PREFIX3(streamp) strm, int flush, int *ret) { struct inflate_state *state = (struct inflate_state *)strm->state; struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); struct dfltcc_param_v0 *param = &dfltcc_state->param; @@ -115,16 +112,14 @@ dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(PREFIX3(streamp) strm, int fl DFLTCC_INFLATE_BREAK : DFLTCC_INFLATE_CONTINUE; } -int ZLIB_INTERNAL dfltcc_was_inflate_used(PREFIX3(streamp) strm) -{ +int ZLIB_INTERNAL dfltcc_was_inflate_used(PREFIX3(streamp) strm) { struct inflate_state *state = (struct inflate_state *)strm->state; struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param; return !param->nt; } -int ZLIB_INTERNAL dfltcc_inflate_disable(PREFIX3(streamp) strm) -{ +int ZLIB_INTERNAL dfltcc_inflate_disable(PREFIX3(streamp) strm) { struct inflate_state *state = (struct inflate_state *)strm->state; struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); diff --git a/arch/x86/crc_folding.c b/arch/x86/crc_folding.c index eae7d28c31..4c63b6abf1 100644 --- a/arch/x86/crc_folding.c +++ b/arch/x86/crc_folding.c @@ -1,5 +1,5 @@ /* - * Compute the CRC32 using a parallelized folding approach with the PCLMULQDQ + * Compute the CRC32 using a parallelized folding approach with the PCLMULQDQ * instruction. * * A white paper describing this algorithm can be found at: diff --git a/arch/x86/deflate_quick.c b/arch/x86/deflate_quick.c index 333be3e6c2..0934913891 100644 --- a/arch/x86/deflate_quick.c +++ b/arch/x86/deflate_quick.c @@ -93,11 +93,11 @@ static inline long compare258(const unsigned char *const src0, const unsigned ch "cmp $256 + 16, %[ax]\n\t" "jb 1b\n\t" -# if !defined(__x86_64__) +# if !defined(__x86_64__) "movzwl -16(%[src0], %[ax]), %[dx]\n\t" -# else +# else "movzwq -16(%[src0], %[ax]), %[dx]\n\t" -# endif +# endif "xorw -16(%[src1], %[ax]), %%dx\n\t" "jnz 3f\n\t" @@ -134,19 +134,19 @@ static inline void quick_send_bits(deflate_state *const s, /* Concatenate the new bits with the bits currently in the buffer */ unsigned out = s->bi_buf | (value1 << s->bi_valid); if (width < 32) { - out |= (value2 << offset2); - /* Shift out the valid LSBs written out. */ - s->bi_buf = out >> (bytes_out * 8); - } else /* width => 32 */ { - unsigned bits_that_fit = 32 - offset2; - unsigned mask = (1 << bits_that_fit) - 1; - /* Zero out the high bits of value2 such that the shift by offset2 will - not cause undefined behavior. */ - out |= ((value2 & mask) << offset2); + out |= (value2 << offset2); + /* Shift out the valid LSBs written out. */ + s->bi_buf = out >> (bytes_out * 8); + } else { /* width => 32 */ + unsigned bits_that_fit = 32 - offset2; + unsigned mask = (1 << bits_that_fit) - 1; + /* Zero out the high bits of value2 such that the shift by offset2 will + not cause undefined behavior. */ + out |= ((value2 & mask) << offset2); - /* Save in s->bi_buf the bits of value2 that do not fit: they will be - written in a next full byte. */ - s->bi_buf = (width == 32) ? 0 : value2 >> bits_that_fit; + /* Save in s->bi_buf the bits of value2 that do not fit: they will be + written in a next full byte. */ + s->bi_buf = (width == 32) ? 0 : value2 >> bits_that_fit; } s->bi_valid = width - (bytes_out * 8); diff --git a/arch/x86/fill_window_sse.c b/arch/x86/fill_window_sse.c index 4a4f5fa2be..275a2d11c0 100644 --- a/arch/x86/fill_window_sse.c +++ b/arch/x86/fill_window_sse.c @@ -95,9 +95,9 @@ ZLIB_INTERNAL void fill_window_sse(deflate_state *s) { } #else unsigned int count; - if (UNLIKELY(s->lookahead == 1)){ + if (UNLIKELY(s->lookahead == 1)) { count = s->insert - 1; - }else{ + } else { count = s->insert; } functable.insert_string(s, str, count); diff --git a/arch/x86/insert_string_sse.c b/arch/x86/insert_string_sse.c index b0cc92dd49..8f4e75d028 100644 --- a/arch/x86/insert_string_sse.c +++ b/arch/x86/insert_string_sse.c @@ -61,9 +61,9 @@ ZLIB_INTERNAL Pos insert_string_sse(deflate_state *const s, const Pos str, unsig s->prev[(str+idx) & s->w_mask] = head; s->head[h & s->hash_mask] = str+idx; if (idx == count-1) - ret = head; + ret = head; } else if (idx == count - 1) { - ret = str + idx; + ret = str + idx; } } return ret; diff --git a/arch/x86/x86.h b/arch/x86/x86.h index 860e64154a..9d6f37569e 100644 --- a/arch/x86/x86.h +++ b/arch/x86/x86.h @@ -1,7 +1,7 @@ - /* cpu.h -- check for CPU features - * Copyright (C) 2013 Intel Corporation Jim Kukunas - * For conditions of distribution and use, see copyright notice in zlib.h - */ +/* cpu.h -- check for CPU features +* Copyright (C) 2013 Intel Corporation Jim Kukunas +* For conditions of distribution and use, see copyright notice in zlib.h +*/ #ifndef CPU_H_ #define CPU_H_ diff --git a/cmake/archdetect.cmake b/cmake/archdetect.cmake index 9a8b9881e2..3c87fddfd6 100644 --- a/cmake/archdetect.cmake +++ b/cmake/archdetect.cmake @@ -45,7 +45,6 @@ else() message(STATUS "Arch detected: '${ARCH}'") endif() - # Base arch detection if("${ARCH}" MATCHES "(x86_64|AMD64|i[3-6]86)") set(BASEARCH "x86") diff --git a/compress.c b/compress.c index 6b493fda50..5adcf653c2 100644 --- a/compress.c +++ b/compress.c @@ -8,9 +8,9 @@ #define ZLIB_INTERNAL #include "zbuild.h" #if defined(ZLIB_COMPAT) -# include "zlib.h" +# include "zlib.h" #else -# include "zlib-ng.h" +# include "zlib-ng.h" #endif /* =========================================================================== diff --git a/crc32.c b/crc32.c index 557067e4be..5570b585e8 100644 --- a/crc32.c +++ b/crc32.c @@ -42,8 +42,7 @@ uint32_t ZEXPORT PREFIX(crc32_z)(uint32_t crc, const unsigned char *buf, size_t #define DO4 DO1; DO1; DO1; DO1 /* ========================================================================= */ -ZLIB_INTERNAL uint32_t crc32_generic(uint32_t crc, const unsigned char *buf, uint64_t len) -{ +ZLIB_INTERNAL uint32_t crc32_generic(uint32_t crc, const unsigned char *buf, uint64_t len) { crc = crc ^ 0xffffffff; #ifdef UNROLL_MORE @@ -224,8 +223,8 @@ ZLIB_INTERNAL void copy_with_crc(PREFIX3(stream) *strm, unsigned char *dst, unsi } /* ========================================================================= */ -static void crc32_combine_gen_(uint32_t *op, z_off64_t len2) -{ + +static void crc32_combine_gen_(uint32_t *op, z_off64_t len2) { uint32_t row; int j; unsigned i; @@ -267,18 +266,16 @@ static void crc32_combine_gen_(uint32_t *op, z_off64_t len2) } /* ========================================================================= */ -void ZEXPORT PREFIX(crc32_combine_gen)(uint32_t *op, z_off_t len2) -{ + +void ZEXPORT PREFIX(crc32_combine_gen)(uint32_t *op, z_off_t len2) { crc32_combine_gen_(op, len2); } -void ZEXPORT PREFIX(crc32_combine_gen64)(uint32_t *op, z_off64_t len2) -{ +void ZEXPORT PREFIX(crc32_combine_gen64)(uint32_t *op, z_off64_t len2) { crc32_combine_gen_(op, len2); } /* ========================================================================= */ -uint32_t ZEXPORT PREFIX(crc32_combine_op)(uint32_t crc1, uint32_t crc2, const uint32_t *op) -{ +uint32_t ZEXPORT PREFIX(crc32_combine_op)(uint32_t crc1, uint32_t crc2, const uint32_t *op) { return gf2_matrix_times(op, crc1) ^ crc2; } diff --git a/deflate.c b/deflate.c index 61c51f6f7d..40f037fd73 100644 --- a/deflate.c +++ b/deflate.c @@ -203,52 +203,52 @@ ZLIB_INTERNAL void slide_hash_c(deflate_state *s) { n = s->hash_size; p = &s->head[n]; #ifdef NOT_TWEAK_COMPILER - do { - unsigned m; - m = *--p; - *p = (Pos)(m >= wsize ? m-wsize : NIL); - } while (--n); + do { + unsigned m; + m = *--p; + *p = (Pos)(m >= wsize ? m-wsize : NIL); + } while (--n); #else - /* As of I make this change, gcc (4.8.*) isn't able to vectorize - * this hot loop using saturated-subtraction on x86-64 architecture. - * To avoid this defect, we can change the loop such that - * o. the pointer advance forward, and - * o. demote the variable 'm' to be local to the loop, and - * choose type "Pos" (instead of 'unsigned int') for the - * variable to avoid unncessary zero-extension. - */ - { - unsigned int i; - Pos *q = p - n; - for (i = 0; i < n; i++) { - Pos m = *q; - Pos t = wsize; - *q++ = (Pos)(m >= t ? m-t: NIL); - } - } + /* As of I make this change, gcc (4.8.*) isn't able to vectorize + * this hot loop using saturated-subtraction on x86-64 architecture. + * To avoid this defect, we can change the loop such that + * o. the pointer advance forward, and + * o. demote the variable 'm' to be local to the loop, and + * choose type "Pos" (instead of 'unsigned int') for the + * variable to avoid unncessary zero-extension. + */ + { + unsigned int i; + Pos *q = p - n; + for (i = 0; i < n; i++) { + Pos m = *q; + Pos t = wsize; + *q++ = (Pos)(m >= t ? m-t: NIL); + } + } #endif /* NOT_TWEAK_COMPILER */ - n = wsize; - p = &s->prev[n]; + n = wsize; + p = &s->prev[n]; #ifdef NOT_TWEAK_COMPILER - do { - unsigned m; - m = *--p; - *p = (Pos)(m >= wsize ? m-wsize : NIL); - /* If n is not on any hash chain, prev[n] is garbage but - * its value will never be used. - */ - } while (--n); + do { + unsigned m; + m = *--p; + *p = (Pos)(m >= wsize ? m-wsize : NIL); + /* If n is not on any hash chain, prev[n] is garbage but + * its value will never be used. + */ + } while (--n); #else - { - unsigned int i; - Pos *q = p - n; - for (i = 0; i < n; i++) { - Pos m = *q; - Pos t = wsize; - *q++ = (Pos)(m >= t ? m-t: NIL); - } - } + { + unsigned int i; + Pos *q = p - n; + for (i = 0; i < n; i++) { + Pos m = *q; + Pos t = wsize; + *q++ = (Pos)(m >= t ? m-t: NIL); + } + } #endif /* NOT_TWEAK_COMPILER */ } @@ -498,7 +498,7 @@ int ZEXPORT PREFIX(deflateSetDictionary)(PREFIX3(stream) *strm, const unsigned c } /* ========================================================================= */ -int ZEXPORT PREFIX(deflateGetDictionary)(PREFIX3(stream) *strm, unsigned char *dictionary, unsigned int *dictLength) { +int ZEXPORT PREFIX(deflateGetDictionary)(PREFIX3(stream) *strm, unsigned char *dictionary, unsigned int *dictLength) { deflate_state *s; unsigned int len; @@ -825,10 +825,10 @@ int ZEXPORT PREFIX(deflate)(PREFIX3(stream) *strm, int flush) { return Z_OK; } - /* Make sure there is something to do and avoid duplicate consecutive - * flushes. For repeated and useless calls with Z_FINISH, we keep - * returning Z_STREAM_END instead of Z_BUF_ERROR. - */ + /* Make sure there is something to do and avoid duplicate consecutive + * flushes. For repeated and useless calls with Z_FINISH, we keep + * returning Z_STREAM_END instead of Z_BUF_ERROR. + */ } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) && flush != Z_FINISH) { ERR_RETURN(strm, Z_BUF_ERROR); @@ -900,8 +900,7 @@ int ZEXPORT PREFIX(deflate)(PREFIX3(stream) *strm, int flush) { s->last_flush = -1; return Z_OK; } - } - else { + } else { put_byte(s, (s->gzhead->text ? 1 : 0) + (s->gzhead->hcrc ? 2 : 0) + (s->gzhead->extra == NULL ? 0 : 4) + @@ -1069,8 +1068,8 @@ int ZEXPORT PREFIX(deflate)(PREFIX3(stream) *strm, int flush) { } flush_pending(strm); if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ - return Z_OK; + s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ + return Z_OK; } } } @@ -1335,9 +1334,9 @@ void ZLIB_INTERNAL fill_window_c(deflate_state *s) { } #else unsigned int count; - if (UNLIKELY(s->lookahead == 1)){ + if (UNLIKELY(s->lookahead == 1)) { count = s->insert - 1; - }else{ + } else { count = s->insert; } functable.insert_string(s,str,count); @@ -1499,8 +1498,7 @@ static block_state deflate_stored(deflate_state *s, int flush) { memcpy(s->window, s->strm->next_in - s->w_size, s->w_size); s->strstart = s->w_size; s->insert = s->strstart; - } - else { + } else { if (s->window_size - s->strstart <= used) { /* Slide the window down. */ s->strstart -= s->w_size; diff --git a/deflate.h b/deflate.h index f8ae93585b..2806d92ad3 100644 --- a/deflate.h +++ b/deflate.h @@ -154,9 +154,9 @@ typedef struct internal_state { unsigned int hash_bits; /* log2(hash_size) */ unsigned int hash_mask; /* hash_size-1 */ - #if !defined(__x86_64__) && !defined(_M_X64) && !defined(__i386) && !defined(_M_IX86) +#if !defined(__x86_64__) && !defined(_M_X64) && !defined(__i386) && !defined(_M_IX86) unsigned int hash_shift; - #endif +#endif /* Number of bits by which ins_h must be shifted at each input * step. It must be such that after MIN_MATCH steps, the oldest * byte no longer takes part in the hash key, that is: @@ -300,7 +300,9 @@ typedef enum { /* Output a byte on the stream. * IN assertion: there is enough room in pending_buf. */ -#define put_byte(s, c) {s->pending_buf[s->pending++] = (unsigned char)(c);} +#define put_byte(s, c) { \ + s->pending_buf[s->pending++] = (unsigned char)(c); \ +} /* =========================================================================== * Output a short LSB first on the stream. @@ -308,10 +310,10 @@ typedef enum { */ static inline void put_short(deflate_state *s, uint16_t w) { #if BYTE_ORDER == BIG_ENDIAN - w = ZSWAP16(w); + w = ZSWAP16(w); #endif - memcpy(&(s->pending_buf[s->pending]), &w, sizeof(uint16_t)); - s->pending += 2; + memcpy(&(s->pending_buf[s->pending]), &w, sizeof(uint16_t)); + s->pending += 2; } #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) @@ -352,10 +354,10 @@ void ZLIB_INTERNAL flush_pending(PREFIX3(streamp) strm); #ifndef ZLIB_DEBUG /* Inline versions of _tr_tally for speed: */ - extern const unsigned char ZLIB_INTERNAL zng_length_code[]; - extern const unsigned char ZLIB_INTERNAL zng_dist_code[]; +extern const unsigned char ZLIB_INTERNAL zng_length_code[]; +extern const unsigned char ZLIB_INTERNAL zng_dist_code[]; -# define zng_tr_tally_lit(s, c, flush) \ +# define zng_tr_tally_lit(s, c, flush) \ { unsigned char cc = (c); \ s->sym_buf[s->sym_next++] = 0; \ s->sym_buf[s->sym_next++] = 0; \ @@ -363,7 +365,7 @@ void ZLIB_INTERNAL flush_pending(PREFIX3(streamp) strm); s->dyn_ltree[cc].Freq++; \ flush = (s->sym_next == s->sym_end); \ } -# define zng_tr_tally_dist(s, distance, length, flush) \ +# define zng_tr_tally_dist(s, distance, length, flush) \ { unsigned char len = (unsigned char)(length); \ unsigned dist = (unsigned)(distance); \ s->sym_buf[s->sym_next++] = dist; \ @@ -375,8 +377,8 @@ void ZLIB_INTERNAL flush_pending(PREFIX3(streamp) strm); flush = (s->sym_next == s->sym_end); \ } #else -# define zng_tr_tally_lit(s, c, flush) flush = zng_tr_tally(s, 0, c) -# define zng_tr_tally_dist(s, distance, length, flush) \ +# define zng_tr_tally_lit(s, c, flush) flush = zng_tr_tally(s, 0, c) +# define zng_tr_tally_dist(s, distance, length, flush) \ flush = zng_tr_tally(s, (unsigned)(distance), (unsigned)(length)) #endif @@ -388,13 +390,13 @@ void ZLIB_INTERNAL flush_pending(PREFIX3(streamp) strm); */ #ifdef NOT_TWEAK_COMPILER -#define TRIGGER_LEVEL 6 +# define TRIGGER_LEVEL 6 #else -#define TRIGGER_LEVEL 5 +# define TRIGGER_LEVEL 5 #endif #if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86) -#define UPDATE_HASH(s, h, i) \ +# define UPDATE_HASH(s, h, i) \ do {\ if (s->level < TRIGGER_LEVEL) \ h = (3483 * (s->window[i]) +\ @@ -407,30 +409,32 @@ void ZLIB_INTERNAL flush_pending(PREFIX3(streamp) strm); 25811* (s->window[i+2])) & s->hash_mask;\ } while (0) #else -# define UPDATE_HASH(s, h, i) (h = (((h) << s->hash_shift) ^ (s->window[i + (MIN_MATCH-1)])) & s->hash_mask) +# define UPDATE_HASH(s, h, i) \ + (h = (((h) << s->hash_shift) ^ (s->window[i + (MIN_MATCH-1)])) & s->hash_mask) #endif #ifdef ZLIB_DEBUG - #define send_code(s, c, tree, bit_buf, bits_valid) { \ +# define send_code(s, c, tree, bit_buf, bits_valid) { \ if (z_verbose > 2) { \ fprintf(stderr, "\ncd %3d ", (c)); \ } \ send_bits(s, tree[c].Code, tree[c].Len, bit_buf, bits_valid); \ } #else /* ZLIB_DEBUG */ - /* Send a code of the given tree. c and tree must not have side effects */ - #define send_code(s, c, tree, bit_buf, bits_valid) send_bits(s, tree[c].Code, tree[c].Len, bit_buf, bits_valid) +/* Send a code of the given tree. c and tree must not have side effects */ +# define send_code(s, c, tree, bit_buf, bits_valid) \ + send_bits(s, tree[c].Code, tree[c].Len, bit_buf, bits_valid) #endif #ifdef ZLIB_DEBUG - #define send_debug_trace(s, value, length) {\ +# define send_debug_trace(s, value, length) {\ Tracevv((stderr, " l %2d v %4x ", length, value));\ Assert(length > 0 && length <= 15, "invalid length");\ s->bits_sent += (unsigned long)length;\ } #else - #define send_debug_trace(s, value, length) {} +# define send_debug_trace(s, value, length) {} #endif /* If not enough room in bit_buf, use (valid) bits from bit_buf and diff --git a/deflate_medium.c b/deflate_medium.c index f320c3c8fa..f694facdd6 100644 --- a/deflate_medium.c +++ b/deflate_medium.c @@ -129,9 +129,9 @@ static void insert_match(deflate_state *s, struct match match) { #warning Call insert_string() MIN_MATCH-3 more times #endif #endif - /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not - * matter since it will be recomputed at next deflate call. - */ + /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not + * matter since it will be recomputed at next deflate call. + */ } } diff --git a/deflate_p.h b/deflate_p.h index b282baece5..1e0b34dc06 100644 --- a/deflate_p.h +++ b/deflate_p.h @@ -36,12 +36,12 @@ static inline Pos insert_string_c(deflate_state *const s, const Pos str, unsigne Pos head = s->head[s->ins_h]; if (head != str+idx) { - s->prev[(str+idx) & s->w_mask] = head; - s->head[s->ins_h] = str+idx; - if (idx == count - 1) - ret = head; + s->prev[(str+idx) & s->w_mask] = head; + s->head[s->ins_h] = str+idx; + if (idx == count - 1) + ret = head; } else if (idx == count - 1) { - ret = str + idx; + ret = str + idx; } } return ret; diff --git a/fallback_builtins.h b/fallback_builtins.h index 3f7005ce4d..3598b7c913 100644 --- a/fallback_builtins.h +++ b/fallback_builtins.h @@ -3,15 +3,14 @@ #include #ifdef X86_CPUID -# include "arch/x86/x86.h" +# include "arch/x86/x86.h" #endif #if defined(_MSC_VER) && !defined(__clang__) /* This is not a general purpose replacement for __builtin_ctzl. The function expects that value is != 0 * Because of that assumption trailing_zero is not initialized and the return value of _BitScanForward is not checked */ -static __forceinline unsigned long __builtin_ctzl(unsigned long value) -{ +static __forceinline unsigned long __builtin_ctzl(unsigned long value) { #ifdef X86_CPUID if (x86_cpu_has_tzcnt) return _tzcnt_u32(value); diff --git a/functable.c b/functable.c index fcdd34cd9b..2519744d1b 100644 --- a/functable.c +++ b/functable.c @@ -62,78 +62,77 @@ ZLIB_INTERNAL void slide_hash_stub(deflate_state *s); /* functable init */ ZLIB_INTERNAL __thread struct functable_s functable = { - fill_window_stub, - insert_string_stub, - adler32_stub, - crc32_stub, - slide_hash_stub - }; + fill_window_stub, + insert_string_stub, + adler32_stub, + crc32_stub, + slide_hash_stub +}; /* stub functions */ ZLIB_INTERNAL Pos insert_string_stub(deflate_state *const s, const Pos str, unsigned int count) { // Initialize default - functable.insert_string=&insert_string_c; + functable.insert_string = &insert_string_c; - #ifdef X86_SSE42_CRC_HASH +#ifdef X86_SSE42_CRC_HASH if (x86_cpu_has_sse42) - functable.insert_string=&insert_string_sse; - #elif defined(__ARM_FEATURE_CRC32) && defined(ARM_ACLE_CRC_HASH) + functable.insert_string = &insert_string_sse; +#elif defined(__ARM_FEATURE_CRC32) && defined(ARM_ACLE_CRC_HASH) if (arm_cpu_has_crc32) - functable.insert_string=&insert_string_acle; - #endif + functable.insert_string = &insert_string_acle; +#endif return functable.insert_string(s, str, count); } ZLIB_INTERNAL void fill_window_stub(deflate_state *s) { // Initialize default - functable.fill_window=&fill_window_c; + functable.fill_window = &fill_window_c; - #if defined(X86_SSE2) - # if !defined(__x86_64__) && !defined(_M_X64) && !defined(X86_NOCHECK_SSE2) +#if defined(X86_SSE2) +# if !defined(__x86_64__) && !defined(_M_X64) && !defined(X86_NOCHECK_SSE2) if (x86_cpu_has_sse2) - # endif - functable.fill_window=&fill_window_sse; - #elif defined(ARM_GETAUXVAL) - functable.fill_window=&fill_window_arm; - #endif +# endif + functable.fill_window = &fill_window_sse; +#elif defined(ARM_GETAUXVAL) + functable.fill_window = &fill_window_arm; +#endif functable.fill_window(s); } ZLIB_INTERNAL void slide_hash_stub(deflate_state *s) { // Initialize default - functable.slide_hash=&slide_hash_c; + functable.slide_hash = &slide_hash_c; - #ifdef X86_SSE2 - # if !defined(__x86_64__) && !defined(_M_X64) && !defined(X86_NOCHECK_SSE2) +#ifdef X86_SSE2 +# if !defined(__x86_64__) && !defined(_M_X64) && !defined(X86_NOCHECK_SSE2) if (x86_cpu_has_sse2) - # endif - functable.slide_hash=&slide_hash_sse2; - #endif +# endif + functable.slide_hash = &slide_hash_sse2; +#endif functable.slide_hash(s); } ZLIB_INTERNAL uint32_t adler32_stub(uint32_t adler, const unsigned char *buf, size_t len) { // Initialize default - functable.adler32=&adler32_c; + functable.adler32 = &adler32_c; - #if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && defined(ARM_NEON_ADLER32) +#if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && defined(ARM_NEON_ADLER32) if (arm_cpu_has_neon) - functable.adler32=&adler32_neon; - #endif + functable.adler32 = &adler32_neon; +#endif return functable.adler32(adler, buf, len); } ZLIB_INTERNAL uint32_t crc32_stub(uint32_t crc, const unsigned char *buf, uint64_t len) { - - Assert(sizeof(uint64_t) >= sizeof(size_t), - "crc32_z takes size_t but internally we have a uint64_t len"); -/* return a function pointer for optimized arches here after a capability test */ + Assert(sizeof(uint64_t) >= sizeof(size_t), + "crc32_z takes size_t but internally we have a uint64_t len"); + /* return a function pointer for optimized arches here after a capability test */ #ifdef DYNAMIC_CRC_TABLE if (crc_table_empty) @@ -142,18 +141,18 @@ ZLIB_INTERNAL uint32_t crc32_stub(uint32_t crc, const unsigned char *buf, uint64 if (sizeof(void *) == sizeof(ptrdiff_t)) { #if BYTE_ORDER == LITTLE_ENDIAN - functable.crc32=crc32_little; + functable.crc32 = crc32_little; # if defined(__ARM_FEATURE_CRC32) && defined(ARM_ACLE_CRC_HASH) - if (arm_cpu_has_crc32) - functable.crc32=crc32_acle; + if (arm_cpu_has_crc32) + functable.crc32 = crc32_acle; # endif #elif BYTE_ORDER == BIG_ENDIAN - functable.crc32=crc32_big; + functable.crc32 = crc32_big; #else # error No endian defined #endif } else { - functable.crc32=crc32_generic; + functable.crc32 = crc32_generic; } return functable.crc32(crc, buf, len); diff --git a/gzguts.h b/gzguts.h index 066617fe9a..0529a70a77 100644 --- a/gzguts.h +++ b/gzguts.h @@ -29,9 +29,9 @@ #include #if defined(ZLIB_COMPAT) -# include "zlib.h" +# include "zlib.h" #else -# include "zlib-ng.h" +# include "zlib-ng.h" #endif #ifdef WIN32 @@ -99,9 +99,9 @@ /* default i/o buffer size -- double this for output when reading (this and twice this must be able to fit in an unsigned type) */ #if defined(S390_DFLTCC_DEFLATE) || defined(S390_DFLTCC_INFLATE) -#define GZBUFSIZE 262144 /* DFLTCC works faster with larger buffers */ +# define GZBUFSIZE 262144 /* DFLTCC works faster with larger buffers */ #else -#define GZBUFSIZE 8192 +# define GZBUFSIZE 8192 #endif /* gzip modes, also provide a little integrity check on the passed structure */ diff --git a/gzread.c b/gzread.c index e041a38170..7b1030266e 100644 --- a/gzread.c +++ b/gzread.c @@ -519,29 +519,31 @@ char * ZEXPORT PREFIX(gzgets)(gzFile file, char *buf, int len) { the contents, let the user worry about that) */ str = buf; left = (unsigned)len - 1; - if (left) do { - /* assure that something is in the output buffer */ - if (state->x.have == 0 && gz_fetch(state) == -1) - return NULL; /* error */ - if (state->x.have == 0) { /* end of file */ - state->past = 1; /* read past end */ - break; /* return what we have */ - } - - /* look for end-of-line in current output buffer */ - n = state->x.have > left ? left : state->x.have; - eol = (unsigned char *)memchr(state->x.next, '\n', n); - if (eol != NULL) - n = (unsigned)(eol - state->x.next) + 1; - - /* copy through end-of-line, or remainder if not found */ - memcpy(buf, state->x.next, n); - state->x.have -= n; - state->x.next += n; - state->x.pos += n; - left -= n; - buf += n; - } while (left && eol == NULL); + if (left) { + do { + /* assure that something is in the output buffer */ + if (state->x.have == 0 && gz_fetch(state) == -1) + return NULL; /* error */ + if (state->x.have == 0) { /* end of file */ + state->past = 1; /* read past end */ + break; /* return what we have */ + } + + /* look for end-of-line in current output buffer */ + n = state->x.have > left ? left : state->x.have; + eol = (unsigned char *)memchr(state->x.next, '\n', n); + if (eol != NULL) + n = (unsigned)(eol - state->x.next) + 1; + + /* copy through end-of-line, or remainder if not found */ + memcpy(buf, state->x.next, n); + state->x.have -= n; + state->x.next += n; + state->x.pos += n; + left -= n; + buf += n; + } while (left && eol == NULL); + } /* return terminated string, or if nothing, end of file */ if (buf == str) diff --git a/infback.c b/infback.c index 50478812cd..a98e05a35c 100644 --- a/infback.c +++ b/infback.c @@ -119,7 +119,7 @@ int ZEXPORT PREFIX(inflateBackInit_)(PREFIX3(stream) *strm, int windowBits, unsi in() should return zero on failure. out() should return non-zero on failure. If either in() or out() fails, than inflateBack() returns a Z_BUF_ERROR. strm->next_in can be checked for NULL to see whether it - was in() or out() that caused in the error. Otherwise, inflateBack() + was in() or out() that caused in the error. Otherwise, inflateBack() returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format error, or Z_MEM_ERROR if it could not allocate memory for the state. inflateBack() can also return Z_STREAM_ERROR if the input parameters diff --git a/inffast.c b/inffast.c index 62cb9513af..1f74967f5e 100644 --- a/inffast.c +++ b/inffast.c @@ -313,11 +313,11 @@ void ZLIB_INTERNAL zng_inflate_fast(PREFIX3(stream) *strm, unsigned long start) out = chunkmemset(out, dist, len); #else if (len < sizeof(uint64_t)) - out = set_bytes(out, out - dist, dist, len); + out = set_bytes(out, out - dist, dist, len); else if (dist == 1) - out = byte_memset(out, len); + out = byte_memset(out, len); else - out = chunk_memset(out, out - dist, dist, len); + out = chunk_memset(out, out - dist, dist, len); #endif } } else if ((op & 64) == 0) { /* 2nd level distance code */ diff --git a/inflate.c b/inflate.c index 2ba094798f..bfaf85fa4e 100644 --- a/inflate.c +++ b/inflate.c @@ -200,8 +200,7 @@ void ZLIB_INTERNAL fixedtables(struct inflate_state *state) { state->distbits = 5; } -int ZLIB_INTERNAL inflate_ensure_window(struct inflate_state *state) -{ +int ZLIB_INTERNAL inflate_ensure_window(struct inflate_state *state) { /* if it hasn't been done already, allocate space for the window */ if (state->window == NULL) { #ifdef INFFAST_CHUNKSIZE diff --git a/inftrees.c b/inftrees.c index 6415f79d29..b7c0e3cb76 100644 --- a/inftrees.c +++ b/inftrees.c @@ -30,7 +30,7 @@ const char zng_inflate_copyright[] = " inflate 1.2.11.f Copyright 1995-2016 Mark longest code or if it is less than the shortest code. */ int ZLIB_INTERNAL zng_inflate_table(codetype type, uint16_t *lens, unsigned codes, - code * *table, unsigned *bits, uint16_t *work) { + code * *table, unsigned *bits, uint16_t *work) { unsigned len; /* a code's length in bits */ unsigned sym; /* index of code symbols */ unsigned min, max; /* minimum and maximum code lengths */ diff --git a/match_p.h b/match_p.h index 742100ac93..ab41aa29d1 100644 --- a/match_p.h +++ b/match_p.h @@ -33,9 +33,9 @@ #if defined(_MSC_VER) && !defined(__clang__) -# if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined(_M_ARM) || defined(_M_ARM64) -# include "fallback_builtins.h" -# endif +# if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined(_M_ARM) || defined(_M_ARM64) +# include "fallback_builtins.h" +# endif #endif @@ -89,7 +89,7 @@ static inline unsigned longest_match(deflate_state *const s, IPos cur_match) { Assert((unsigned long)s->strstart <= s->window_size - MIN_LOOKAHEAD, "need lookahead"); do { if (cur_match >= s->strstart) { - break; + break; } match = s->window + cur_match; @@ -210,7 +210,7 @@ static inline unsigned longest_match(deflate_state *const s, IPos cur_match) { do { unsigned char *match; if (cur_match >= s->strstart) { - break; + break; } match = s->window + cur_match; @@ -253,28 +253,28 @@ static inline unsigned longest_match(deflate_state *const s, IPos cur_match) { memcpy(&mval, match, sizeof(mval)); memcpy(&sval, scan, sizeof(sval)); if (mval != sval) - break; + break; match += sizeof(mval); scan += sizeof(sval); memcpy(&mval, match, sizeof(mval)); memcpy(&sval, scan, sizeof(sval)); if (mval != sval) - break; + break; match += sizeof(mval); scan += sizeof(sval); memcpy(&mval, match, sizeof(mval)); memcpy(&sval, scan, sizeof(sval)); if (mval != sval) - break; + break; match += sizeof(mval); scan += sizeof(sval); memcpy(&mval, match, sizeof(mval)); memcpy(&sval, scan, sizeof(sval)); if (mval != sval) - break; + break; match += sizeof(mval); scan += sizeof(sval); } while (scan < strend); @@ -418,7 +418,7 @@ static inline unsigned longest_match(deflate_state *const s, IPos cur_match) { do { if (cur_match >= strstart) { - break; + break; } /* Skip to next match if the match length cannot increase diff --git a/memcopy.h b/memcopy.h index 192fbd42b6..47bfbdac78 100644 --- a/memcopy.h +++ b/memcopy.h @@ -2,35 +2,35 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ #ifndef MEMCOPY_H_ - #define MEMCOPY_H_ +#define MEMCOPY_H_ - #include "zendian.h" +#include "zendian.h" /* Load 64 bits from IN and place the bytes at offset BITS in the result. */ static inline uint64_t load_64_bits(const unsigned char *in, unsigned bits) { - uint64_t chunk; - memcpy(&chunk, in, sizeof(chunk)); - - #if BYTE_ORDER == LITTLE_ENDIAN - return chunk << bits; - #else - return ZSWAP64(chunk) << bits; - #endif + uint64_t chunk; + memcpy(&chunk, in, sizeof(chunk)); + +#if BYTE_ORDER == LITTLE_ENDIAN + return chunk << bits; +#else + return ZSWAP64(chunk) << bits; +#endif } - #if defined(__ARM_NEON__) || defined(__ARM_NEON) - #include +#if defined(__ARM_NEON__) || defined(__ARM_NEON) +#include typedef uint8x16_t inffast_chunk_t; - #define INFFAST_CHUNKSIZE sizeof(inffast_chunk_t) - #endif +#define INFFAST_CHUNKSIZE sizeof(inffast_chunk_t) +#endif - #if defined(X86_SSE2) - #include +#if defined(X86_SSE2) +#include typedef __m128i inffast_chunk_t; - #define INFFAST_CHUNKSIZE sizeof(inffast_chunk_t) - #endif +#define INFFAST_CHUNKSIZE sizeof(inffast_chunk_t) +#endif - #ifdef INFFAST_CHUNKSIZE +#ifdef INFFAST_CHUNKSIZE /* Ask the compiler to perform a wide, unaligned load with an machine instruction appropriate for the inffast_chunk_t type. @@ -127,46 +127,46 @@ static inline unsigned char* chunkunroll(unsigned char *out, unsigned *dist, uns } static inline inffast_chunk_t chunkmemset_1(unsigned char *from) { - #if defined(X86_SSE2) +#if defined(X86_SSE2) int8_t c; memcpy(&c, from, sizeof(c)); return _mm_set1_epi8(c); - #elif defined(__ARM_NEON__) || defined(__ARM_NEON) +#elif defined(__ARM_NEON__) || defined(__ARM_NEON) return vld1q_dup_u8(from); - #endif +#endif } static inline inffast_chunk_t chunkmemset_2(unsigned char *from) { int16_t c; memcpy(&c, from, sizeof(c)); - #if defined(X86_SSE2) +#if defined(X86_SSE2) return _mm_set1_epi16(c); - #elif defined(__ARM_NEON__) || defined(__ARM_NEON) +#elif defined(__ARM_NEON__) || defined(__ARM_NEON) return vreinterpretq_u8_s16(vdupq_n_s16(c)); - #endif +#endif } static inline inffast_chunk_t chunkmemset_4(unsigned char *from) { int32_t c; memcpy(&c, from, sizeof(c)); - #if defined(X86_SSE2) +#if defined(X86_SSE2) return _mm_set1_epi32(c); - #elif defined(__ARM_NEON__) || defined(__ARM_NEON) +#elif defined(__ARM_NEON__) || defined(__ARM_NEON) return vreinterpretq_u8_s32(vdupq_n_s32(c)); - #endif +#endif } static inline inffast_chunk_t chunkmemset_8(unsigned char *from) { - #if defined(X86_SSE2) +#if defined(X86_SSE2) int64_t c; memcpy(&c, from, sizeof(c)); return _mm_set1_epi64x(c); - #elif defined(__ARM_NEON__) || defined(__ARM_NEON) +#elif defined(__ARM_NEON__) || defined(__ARM_NEON) return vcombine_u8(vld1_u8(from), vld1_u8(from)); - #endif +#endif } - #if defined(__ARM_NEON__) || defined(__ARM_NEON) +#if defined(__ARM_NEON__) || defined(__ARM_NEON) static inline unsigned char *chunkmemset_3(unsigned char *out, unsigned char *from, unsigned dist, unsigned len) { uint8x8x3_t chunks; unsigned sz = sizeof(chunks); @@ -197,9 +197,9 @@ static inline unsigned char *chunkmemset_3(unsigned char *out, unsigned char *fr out = chunkunroll(out, &dist, &rem); return chunkcopy(out, out - dist, rem); } - #endif +#endif - #if defined(__aarch64__) || defined(_M_ARM64) +#if defined(__aarch64__) || defined(_M_ARM64) static inline unsigned char *chunkmemset_6(unsigned char *out, unsigned char *from, unsigned dist, unsigned len) { uint16x8x3_t chunks; unsigned sz = sizeof(chunks); @@ -230,11 +230,11 @@ static inline unsigned char *chunkmemset_6(unsigned char *out, unsigned char *fr out = chunkunroll(out, &dist, &rem); return chunkcopy(out, out - dist, rem); } - #endif +#endif /* Copy DIST bytes from OUT - DIST into OUT + DIST * k, for 0 <= k < LEN/DIST. Return OUT + LEN. */ static inline unsigned char *chunkmemset(unsigned char *out, unsigned dist, unsigned len) { - /* Debug performance related issues when len < sizeof(uint64_t): + /* Debug performance related issues when len < sizeof(uint64_t): Assert(len >= sizeof(uint64_t), "chunkmemset should be called on larger chunks"); */ Assert(dist > 0, "cannot have a distance 0"); @@ -258,18 +258,18 @@ static inline unsigned char *chunkmemset(unsigned char *out, unsigned dist, unsi chunk = chunkmemset_2(from); break; } - #if defined(__ARM_NEON__) || defined(__ARM_NEON) +#if defined(__ARM_NEON__) || defined(__ARM_NEON) case 3: - return chunkmemset_3(out, from, dist, len); - #endif + return chunkmemset_3(out, from, dist, len); +#endif case 4: { chunk = chunkmemset_4(from); break; } - #if defined(__aarch64__) || defined(_M_ARM64) +#if defined(__aarch64__) || defined(_M_ARM64) case 6: return chunkmemset_6(out, from, dist, len); - #endif +#endif case 8: { chunk = chunkmemset_8(from); break; @@ -301,9 +301,9 @@ static inline unsigned char *chunkmemset(unsigned char *out, unsigned dist, unsi static inline unsigned char* chunkmemsetsafe(unsigned char *out, unsigned dist, unsigned len, unsigned left) { if (left < (unsigned)(3 * INFFAST_CHUNKSIZE)) { while (len > 0) { - *out = *(out - dist); - out++; - --len; + *out = *(out - dist); + out++; + --len; } return out; } @@ -311,7 +311,7 @@ static inline unsigned char* chunkmemsetsafe(unsigned char *out, unsigned dist, return chunkmemset(out, dist, len); } - #else /* INFFAST_CHUNKSIZE */ +#else /* INFFAST_CHUNKSIZE */ static inline unsigned char *copy_1_bytes(unsigned char *out, unsigned char *from) { *out++ = *from; @@ -366,12 +366,12 @@ static inline unsigned char *copy_8_bytes(unsigned char *out, unsigned char *fro static inline unsigned char *copy_bytes(unsigned char *out, unsigned char *from, unsigned len) { Assert(len < 8, "copy_bytes should be called with less than 8 bytes"); - #ifndef UNALIGNED_OK +#ifndef UNALIGNED_OK while (len--) { *out++ = *from++; } return out; - #else +#else switch (len) { case 7: return copy_7_bytes(out, from); @@ -394,20 +394,20 @@ static inline unsigned char *copy_bytes(unsigned char *out, unsigned char *from, } return out; - #endif /* UNALIGNED_OK */ +#endif /* UNALIGNED_OK */ } /* Copy LEN bytes (7 or fewer) from FROM into OUT. Return OUT + LEN. */ static inline unsigned char *set_bytes(unsigned char *out, unsigned char *from, unsigned dist, unsigned len) { Assert(len < 8, "set_bytes should be called with less than 8 bytes"); - #ifndef UNALIGNED_OK +#ifndef UNALIGNED_OK (void)dist; while (len--) { *out++ = *from++; } return out; - #else +#else if (dist >= len) return copy_bytes(out, from, len); @@ -498,7 +498,7 @@ static inline unsigned char *set_bytes(unsigned char *out, unsigned char *from, } } return out; - #endif /* UNALIGNED_OK */ +#endif /* UNALIGNED_OK */ } /* Byte by byte semantics: copy LEN bytes from OUT + DIST and write them to OUT. Return OUT + LEN. */ @@ -671,5 +671,5 @@ static inline unsigned char *chunk_copy(unsigned char *out, unsigned char *from, return chunk_memcpy(out, from, len); } - #endif /* INFFAST_CHUNKSIZE */ +#endif /* INFFAST_CHUNKSIZE */ #endif /* MEMCOPY_H_ */ diff --git a/test/example.c b/test/example.c index 8309178e0d..0714a291e4 100644 --- a/test/example.c +++ b/test/example.c @@ -56,8 +56,7 @@ static free_func zfree = NULL; /* =========================================================================== * Test compress() and uncompress() */ -void test_compress(unsigned char *compr, z_size_t comprLen, unsigned char *uncompr, z_size_t uncomprLen) -{ +void test_compress(unsigned char *compr, z_size_t comprLen, unsigned char *uncompr, z_size_t uncomprLen) { int err; size_t len = strlen(hello)+1; @@ -80,8 +79,7 @@ void test_compress(unsigned char *compr, z_size_t comprLen, unsigned char *uncom /* =========================================================================== * Test read/write of .gz files */ -void test_gzio(const char *fname, unsigned char *uncompr, z_size_t uncomprLen) -{ +void test_gzio(const char *fname, unsigned char *uncompr, z_size_t uncomprLen) { #ifdef NO_GZCOMPRESS fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n"); #else @@ -161,8 +159,7 @@ void test_gzio(const char *fname, unsigned char *uncompr, z_size_t uncomprLen) /* =========================================================================== * Test deflate() with small buffers */ -void test_deflate(unsigned char *compr, size_t comprLen) -{ +void test_deflate(unsigned char *compr, size_t comprLen) { PREFIX3(stream) c_stream; /* compression stream */ int err; size_t len = strlen(hello)+1; @@ -199,8 +196,7 @@ void test_deflate(unsigned char *compr, size_t comprLen) /* =========================================================================== * Test inflate() with small buffers */ -void test_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) -{ +void test_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) { int err; PREFIX3(stream) d_stream; /* decompression stream */ @@ -242,8 +238,7 @@ static unsigned int diff; /* =========================================================================== * Test deflate() with large buffers and dynamic change of compression level */ -void test_large_deflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen, int zng_params) -{ +void test_large_deflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen, int zng_params) { PREFIX3(stream) c_stream; /* compression stream */ int err; #ifndef ZLIB_COMPAT @@ -346,8 +341,7 @@ void test_large_deflate(unsigned char *compr, size_t comprLen, unsigned char *un /* =========================================================================== * Test inflate() with large buffers */ -void test_large_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) -{ +void test_large_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) { int err; PREFIX3(stream) d_stream; /* decompression stream */ @@ -387,8 +381,7 @@ void test_large_inflate(unsigned char *compr, size_t comprLen, unsigned char *un /* =========================================================================== * Test deflate() with full flush */ -void test_flush(unsigned char *compr, z_size_t *comprLen) -{ +void test_flush(unsigned char *compr, z_size_t *comprLen) { PREFIX3(stream) c_stream; /* compression stream */ int err; unsigned int len = (unsigned int)strlen(hello)+1; @@ -423,8 +416,7 @@ void test_flush(unsigned char *compr, z_size_t *comprLen) /* =========================================================================== * Test inflateSync() */ -void test_sync(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) -{ +void test_sync(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) { int err; PREFIX3(stream) d_stream; /* decompression stream */ @@ -464,8 +456,7 @@ void test_sync(unsigned char *compr, size_t comprLen, unsigned char *uncompr, si /* =========================================================================== * Test deflate() with preset dictionary */ -void test_dict_deflate(unsigned char *compr, size_t comprLen) -{ +void test_dict_deflate(unsigned char *compr, size_t comprLen) { PREFIX3(stream) c_stream; /* compression stream */ int err; @@ -500,8 +491,7 @@ void test_dict_deflate(unsigned char *compr, size_t comprLen) /* =========================================================================== * Test inflate() with a preset dictionary */ -void test_dict_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) -{ +void test_dict_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) { int err; PREFIX3(stream) d_stream; /* decompression stream */ @@ -548,8 +538,7 @@ void test_dict_inflate(unsigned char *compr, size_t comprLen, unsigned char *unc /* =========================================================================== * Test deflateBound() with small buffers */ -void test_deflate_bound(void) -{ +void test_deflate_bound(void) { PREFIX3(stream) c_stream; /* compression stream */ int err; unsigned int len = (unsigned int)strlen(hello)+1; @@ -594,8 +583,7 @@ void test_deflate_bound(void) /* =========================================================================== * Test deflateCopy() with small buffers */ -void test_deflate_copy(unsigned char *compr, size_t comprLen) -{ +void test_deflate_copy(unsigned char *compr, size_t comprLen) { PREFIX3(stream) c_stream, c_stream_copy; /* compression stream */ int err; size_t len = strlen(hello)+1; @@ -643,8 +631,7 @@ void test_deflate_copy(unsigned char *compr, size_t comprLen) /* =========================================================================== * Test deflateGetDictionary() with small buffers */ -void test_deflate_get_dict(unsigned char *compr, size_t comprLen) -{ +void test_deflate_get_dict(unsigned char *compr, size_t comprLen) { PREFIX3(stream) c_stream; /* compression stream */ int err; unsigned char *dictNew = NULL; @@ -689,8 +676,7 @@ void test_deflate_get_dict(unsigned char *compr, size_t comprLen) /* =========================================================================== * Test deflatePending() with small buffers */ -void test_deflate_pending(unsigned char *compr, size_t comprLen) -{ +void test_deflate_pending(unsigned char *compr, size_t comprLen) { PREFIX3(stream) c_stream; /* compression stream */ int err; int *bits = calloc(256, 1); @@ -741,8 +727,7 @@ void test_deflate_pending(unsigned char *compr, size_t comprLen) /* =========================================================================== * Test deflatePrime() with small buffers */ -void test_deflate_prime(unsigned char *compr, size_t comprLen) -{ +void test_deflate_prime(unsigned char *compr, size_t comprLen) { PREFIX3(stream) c_stream; /* compression stream */ int err; int bits = 0; @@ -789,8 +774,7 @@ void test_deflate_prime(unsigned char *compr, size_t comprLen) /* =========================================================================== * Test deflateSetHeader() with small buffers */ -void test_deflate_set_header(unsigned char *compr, size_t comprLen) -{ +void test_deflate_set_header(unsigned char *compr, size_t comprLen) { PREFIX(gz_header) *head = calloc(256, 1); PREFIX3(stream) c_stream; /* compression stream */ int err; @@ -838,8 +822,7 @@ void test_deflate_set_header(unsigned char *compr, size_t comprLen) /* =========================================================================== * Test deflateTune() with small buffers */ -void test_deflate_tune(unsigned char *compr, size_t comprLen) -{ +void test_deflate_tune(unsigned char *compr, size_t comprLen) { PREFIX3(stream) c_stream; /* compression stream */ int err; int good_length = 3; @@ -886,8 +869,7 @@ void test_deflate_tune(unsigned char *compr, size_t comprLen) /* =========================================================================== * Usage: example [output.gz [input.gz]] */ -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned char *compr, *uncompr; z_size_t comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */ z_size_t uncomprLen = comprLen; diff --git a/test/fuzz/checksum_fuzzer.c b/test/fuzz/checksum_fuzzer.c index 34163e4c97..18bebc32e2 100644 --- a/test/fuzz/checksum_fuzzer.c +++ b/test/fuzz/checksum_fuzzer.c @@ -14,71 +14,71 @@ #endif int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataLen) { - uint32_t crc0 = PREFIX(crc32)(0L, NULL, 0); - uint32_t crc1 = crc0; - uint32_t crc2 = crc0; - uint32_t adler0 = PREFIX(adler32)(0L, NULL, 0); - uint32_t adler1 = adler0; - uint32_t adler2 = adler0; - uint32_t combine1, combine2; - /* Checksum with a buffer of size equal to the first byte in the input. */ - uint32_t buffSize = data[0]; - uint32_t offset = 0; - uint32_t op[32]; + uint32_t crc0 = PREFIX(crc32)(0L, NULL, 0); + uint32_t crc1 = crc0; + uint32_t crc2 = crc0; + uint32_t adler0 = PREFIX(adler32)(0L, NULL, 0); + uint32_t adler1 = adler0; + uint32_t adler2 = adler0; + uint32_t combine1, combine2; + /* Checksum with a buffer of size equal to the first byte in the input. */ + uint32_t buffSize = data[0]; + uint32_t offset = 0; + uint32_t op[32]; - /* Discard inputs larger than 1Mb. */ - static size_t kMaxSize = 1024 * 1024; - if (dataLen < 1 || dataLen > kMaxSize) - return 0; + /* Discard inputs larger than 1Mb. */ + static size_t kMaxSize = 1024 * 1024; + if (dataLen < 1 || dataLen > kMaxSize) + return 0; - /* Make sure the buffer has at least a byte. */ - if (buffSize == 0) - ++buffSize; + /* Make sure the buffer has at least a byte. */ + if (buffSize == 0) + ++buffSize; - /* CRC32 */ - PREFIX(crc32_combine_gen)(op, buffSize); - for (offset = 0; offset + buffSize <= dataLen; offset += buffSize) { - uint32_t crc3 = PREFIX(crc32_z)(crc0, data + offset, buffSize); - 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; - } - crc1 = PREFIX(crc32_z)(crc1, data + offset, dataLen % buffSize); + /* CRC32 */ + PREFIX(crc32_combine_gen)(op, buffSize); + for (offset = 0; offset + buffSize <= dataLen; offset += buffSize) { + uint32_t crc3 = PREFIX(crc32_z)(crc0, data + offset, buffSize); + 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; + } + crc1 = PREFIX(crc32_z)(crc1, data + offset, dataLen % buffSize); - crc2 = PREFIX(crc32_z)(crc2, data, dataLen); + crc2 = PREFIX(crc32_z)(crc2, data, dataLen); - assert(crc1 == crc2); - (void)crc1; - (void)crc2; - combine1 = PREFIX(crc32_combine)(crc1, crc2, (z_off_t)dataLen); - combine2 = PREFIX(crc32_combine)(crc1, crc1, (z_off_t)dataLen); - assert(combine1 == combine2); + assert(crc1 == crc2); + (void)crc1; + (void)crc2; + combine1 = PREFIX(crc32_combine)(crc1, crc2, (z_off_t)dataLen); + combine2 = PREFIX(crc32_combine)(crc1, crc1, (z_off_t)dataLen); + assert(combine1 == combine2); - /* Fast CRC32 combine. */ - PREFIX(crc32_combine_gen)(op, (z_off_t)dataLen); - combine1 = PREFIX(crc32_combine_op)(crc1, crc2, op); - combine2 = PREFIX(crc32_combine_op)(crc2, crc1, op); - assert(combine1 == combine2); - combine1 = PREFIX(crc32_combine)(crc1, crc2, (z_off_t)dataLen); - combine2 = PREFIX(crc32_combine_op)(crc2, crc1, op); - assert(combine1 == combine2); + /* Fast CRC32 combine. */ + PREFIX(crc32_combine_gen)(op, (z_off_t)dataLen); + combine1 = PREFIX(crc32_combine_op)(crc1, crc2, op); + combine2 = PREFIX(crc32_combine_op)(crc2, crc1, op); + assert(combine1 == combine2); + combine1 = PREFIX(crc32_combine)(crc1, crc2, (z_off_t)dataLen); + combine2 = PREFIX(crc32_combine_op)(crc2, crc1, op); + assert(combine1 == combine2); - /* Adler32 */ - for (offset = 0; offset + buffSize <= dataLen; offset += buffSize) - adler1 = PREFIX(adler32_z)(adler1, data + offset, buffSize); - adler1 = PREFIX(adler32_z)(adler1, data + offset, dataLen % buffSize); + /* Adler32 */ + for (offset = 0; offset + buffSize <= dataLen; offset += buffSize) + adler1 = PREFIX(adler32_z)(adler1, data + offset, buffSize); + adler1 = PREFIX(adler32_z)(adler1, data + offset, dataLen % buffSize); - adler2 = PREFIX(adler32_z)(adler2, data, dataLen); + adler2 = PREFIX(adler32_z)(adler2, data, dataLen); - assert(adler1 == adler2); - (void)adler1; - (void)adler2; - combine1 = PREFIX(adler32_combine)(adler1, adler2, (z_off_t)dataLen); - combine2 = PREFIX(adler32_combine)(adler1, adler1, (z_off_t)dataLen); - assert(combine1 == combine2); + assert(adler1 == adler2); + (void)adler1; + (void)adler2; + combine1 = PREFIX(adler32_combine)(adler1, adler2, (z_off_t)dataLen); + combine2 = PREFIX(adler32_combine)(adler1, adler1, (z_off_t)dataLen); + assert(combine1 == combine2); - /* This function must return 0. */ - return 0; + /* This function must return 0. */ + return 0; } diff --git a/test/fuzz/example_dict_fuzzer.c b/test/fuzz/example_dict_fuzzer.c index 86e8fb8a04..3245c2b40a 100644 --- a/test/fuzz/example_dict_fuzzer.c +++ b/test/fuzz/example_dict_fuzzer.c @@ -30,8 +30,7 @@ static unsigned long dictId; /* Adler32 value of the dictionary */ /* =========================================================================== * Test deflate() with preset dictionary */ -void test_dict_deflate(unsigned char **compr, size_t *comprLen) -{ +void test_dict_deflate(unsigned char **compr, size_t *comprLen) { PREFIX3(stream) c_stream; /* compression stream */ int err; int level = data[0] % 11 - 1; /* [-1..9] @@ -58,7 +57,7 @@ void test_dict_deflate(unsigned char **compr, size_t *comprLen) /* deflate would fail for no-compression or for speed levels. */ if (level == 0 || level == 1) - level = -1; + level = -1; c_stream.zalloc = zalloc; c_stream.zfree = zfree; diff --git a/test/fuzz/minigzip_fuzzer.c b/test/fuzz/minigzip_fuzzer.c index 1a99fd7aac..321f99ccd4 100644 --- a/test/fuzz/minigzip_fuzzer.c +++ b/test/fuzz/minigzip_fuzzer.c @@ -16,9 +16,9 @@ #include "zbuild.h" #ifdef ZLIB_COMPAT -# include "zlib.h" +# include "zlib.h" #else -# include "zlib-ng.h" +# include "zlib-ng.h" #endif #include #include @@ -49,7 +49,7 @@ #if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE) #ifndef WIN32 /* unlink already in stdio.h for WIN32 */ - extern int unlink (const char *); +extern int unlink (const char *); #endif #endif @@ -77,8 +77,7 @@ int main (int argc, char *argv[]); /* =========================================================================== * Display error message and exit */ -void error(const char *msg) -{ +void error(const char *msg) { fprintf(stderr, "%s: %s\n", prog, msg); exit(1); } @@ -87,8 +86,7 @@ void error(const char *msg) * Compress input to output then close both files. */ -void gz_compress(FILE *in, gzFile out) -{ +void gz_compress(FILE *in, gzFile out) { char buf[BUFLEN]; int len; int err; @@ -121,8 +119,7 @@ void gz_compress(FILE *in, gzFile out) /* Try compressing the input file at once using mmap. Return Z_OK if * if success, Z_ERRNO otherwise. */ -int gz_compress_mmap(FILE *in, gzFile out) -{ +int gz_compress_mmap(FILE *in, gzFile out) { int len; int err; int ifd = fileno(in); @@ -154,8 +151,7 @@ int gz_compress_mmap(FILE *in, gzFile out) /* =========================================================================== * Uncompress input to output then close both files. */ -void gz_uncompress(gzFile in, FILE *out) -{ +void gz_uncompress(gzFile in, FILE *out) { char buf[BUFLENW]; int len; int err; @@ -179,10 +175,9 @@ void gz_uncompress(gzFile in, FILE *out) * Compress the given file: create a corresponding .gz file and remove the * original. */ -void file_compress(char *file, char *mode) -{ +void file_compress(char *file, char *mode) { char outfile[MAX_NAME_LEN]; - FILE *in; + FILE *in; gzFile out; if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) { @@ -211,11 +206,10 @@ void file_compress(char *file, char *mode) /* =========================================================================== * Uncompress the given file and remove the original. */ -void file_uncompress(char *file) -{ +void file_uncompress(char *file) { char buf[MAX_NAME_LEN]; char *infile, *outfile; - FILE *out; + FILE *out; gzFile in; size_t len = strlen(file); diff --git a/test/infcover.c b/test/infcover.c index 2b8ff974a3..febbf13d95 100644 --- a/test/infcover.c +++ b/test/infcover.c @@ -67,8 +67,7 @@ struct mem_zone { }; /* memory allocation routine to pass to zlib */ -static void *mem_alloc(void *mem, unsigned count, unsigned size) -{ +static void *mem_alloc(void *mem, unsigned count, unsigned size) { void *ptr; struct mem_item *item; struct mem_zone *zone = mem; @@ -108,8 +107,7 @@ static void *mem_alloc(void *mem, unsigned count, unsigned size) } /* memory free routine to pass to zlib */ -static void mem_free(void *mem, void *ptr) -{ +static void mem_free(void *mem, void *ptr) { struct mem_item *item, *next; struct mem_zone *zone = mem; @@ -154,8 +152,7 @@ static void mem_free(void *mem, void *ptr) /* set up a controlled memory allocation space for monitoring, set the stream parameters to the controlled routines, with opaque pointing to the space */ -static void mem_setup(z_stream *strm) -{ +static void mem_setup(z_stream *strm) { struct mem_zone *zone; zone = malloc(sizeof(struct mem_zone)); @@ -172,32 +169,28 @@ static void mem_setup(z_stream *strm) } /* set a limit on the total memory allocation, or 0 to remove the limit */ -static void mem_limit(z_stream *strm, size_t limit) -{ +static void mem_limit(z_stream *strm, size_t limit) { struct mem_zone *zone = strm->opaque; zone->limit = limit; } /* show the current total requested allocations in bytes */ -static void mem_used(z_stream *strm, char *prefix) -{ +static void mem_used(z_stream *strm, char *prefix) { struct mem_zone *zone = strm->opaque; fprintf(stderr, "%s: %zu allocated\n", prefix, zone->total); } /* show the high water allocation in bytes */ -static void mem_high(z_stream *strm, char *prefix) -{ +static void mem_high(z_stream *strm, char *prefix) { struct mem_zone *zone = strm->opaque; fprintf(stderr, "%s: %zu high water mark\n", prefix, zone->highwater); } /* release the memory allocation zone -- if there are any surprises, notify */ -static void mem_done(z_stream *strm, char *prefix) -{ +static void mem_done(z_stream *strm, char *prefix) { int count = 0; struct mem_item *item, *next; struct mem_zone *zone = strm->opaque; @@ -241,8 +234,7 @@ static void mem_done(z_stream *strm, char *prefix) by a delimiter, where that single digit writes a byte. The returned data is allocated and must eventually be freed. NULL is returned if out of memory. If the length is not needed, then len can be NULL. */ -static unsigned char *h2b(const char *hex, unsigned *len) -{ +static unsigned char *h2b(const char *hex, unsigned *len) { unsigned char *in, *re; unsigned next, val; @@ -280,8 +272,7 @@ static unsigned char *h2b(const char *hex, unsigned *len) header information is collected with inflateGetHeader(). If a zlib stream is looking for a dictionary, then an empty dictionary is provided. inflate() is run until all of the input data is consumed. */ -static void inf(char *hex, char *what, unsigned step, int win, unsigned len, int err) -{ +static void inf(char *hex, char *what, unsigned step, int win, unsigned len, int err) { int ret; unsigned have; unsigned char *in, *out; @@ -345,8 +336,7 @@ static void inf(char *hex, char *what, unsigned step, int win, unsigned len, int } /* cover all of the lines in inflate.c up to inflate() */ -static void cover_support(void) -{ +static void cover_support(void) { int ret; z_stream strm; @@ -383,8 +373,7 @@ static void cover_support(void) } /* cover all inflate() header and trailer cases and code after inflate() */ -static void cover_wrap(void) -{ +static void cover_wrap(void) { int ret; z_stream strm, copy; unsigned char dict[257]; @@ -442,8 +431,7 @@ static void cover_wrap(void) } /* input and output functions for inflateBack() */ -static unsigned pull(void *desc, const unsigned char **buf) -{ +static unsigned pull(void *desc, const unsigned char **buf) { static unsigned int next = 0; static unsigned char dat[] = {0x63, 0, 2, 0}; struct inflate_state *state; @@ -458,15 +446,13 @@ static unsigned pull(void *desc, const unsigned char **buf) return next < sizeof(dat) ? (*buf = dat + next++, 1) : 0; } -static int push(void *desc, unsigned char *buf, unsigned len) -{ +static int push(void *desc, unsigned char *buf, unsigned len) { buf += len; return desc != NULL; /* force error if desc not null */ } /* cover inflateBack() up to common deflate data cases and after those */ -static void cover_back(void) -{ +static void cover_back(void) { int ret; z_stream strm; unsigned char win[32768]; @@ -502,8 +488,7 @@ static void cover_back(void) } /* do a raw inflate of data in hexadecimal with both inflate and inflateBack */ -static int try(char *hex, char *id, int err) -{ +static int try(char *hex, char *id, int err) { int ret; unsigned len, size; unsigned char *in, *out, *win; @@ -576,8 +561,7 @@ static int try(char *hex, char *id, int err) } /* cover deflate data cases in both inflate() and inflateBack() */ -static void cover_inflate(void) -{ +static void cover_inflate(void) { try("0 0 0 0 0", "invalid stored block lengths", 1); try("3 0", "fixed", 0); try("6", "invalid block type", 1); @@ -612,8 +596,7 @@ static void cover_inflate(void) } /* cover remaining lines in inftrees.c */ -static void cover_trees(void) -{ +static void cover_trees(void) { int ret; unsigned bits; uint16_t lens[16], work[16]; @@ -636,8 +619,7 @@ static void cover_trees(void) } /* cover remaining inffast.c decoding and window copying */ -static void cover_fast(void) -{ +static void cover_fast(void) { inf("e5 e0 81 ad 6d cb b2 2c c9 01 1e 59 63 ae 7d ee fb 4d fd b5 35 41 68" " ff 7f 0f 0 0 0", "fast length extra bits", 0, -8, 258, Z_DATA_ERROR); inf("25 fd 81 b5 6d 59 b6 6a 49 ea af 35 6 34 eb 8c b9 f6 b9 1e ef 67 49" @@ -656,8 +638,7 @@ static void cover_fast(void) Z_STREAM_END); } -int main(void) -{ +int main(void) { fprintf(stderr, "%s\n", zlibVersion()); cover_support(); cover_wrap(); diff --git a/test/minigzip.c b/test/minigzip.c index 935ebb9e1f..14b2e51657 100644 --- a/test/minigzip.c +++ b/test/minigzip.c @@ -19,9 +19,9 @@ #include "zbuild.h" #ifdef ZLIB_COMPAT -# include "zlib.h" +# include "zlib.h" #else -# include "zlib-ng.h" +# include "zlib-ng.h" #endif #include @@ -52,7 +52,7 @@ #if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE) #ifndef WIN32 /* unlink already in stdio.h for WIN32 */ - extern int unlink (const char *); +extern int unlink (const char *); #endif #endif @@ -62,9 +62,9 @@ #define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1) #if defined(S390_DFLTCC_DEFLATE) || defined(S390_DFLTCC_INFLATE) -#define BUFLEN 262144 /* DFLTCC works faster with larger buffers */ +# define BUFLEN 262144 /* DFLTCC works faster with larger buffers */ #else -#define BUFLEN 16384 /* read buffer size */ +# define BUFLEN 16384 /* read buffer size */ #endif #define BUFLENW (BUFLEN * 3) /* write buffer size */ #define MAX_NAME_LEN 1024 @@ -72,20 +72,19 @@ static char *prog; void error (const char *msg); -void gz_compress (FILE *in, gzFile out); +void gz_compress (FILE *in, gzFile out); #ifdef USE_MMAP -int gz_compress_mmap (FILE *in, gzFile out); +int gz_compress_mmap (FILE *in, gzFile out); #endif -void gz_uncompress (gzFile in, FILE *out); -void file_compress (char *file, char *mode); -void file_uncompress (char *file); +void gz_uncompress (gzFile in, FILE *out); +void file_compress (char *file, char *mode); +void file_uncompress (char *file); int main (int argc, char *argv[]); /* =========================================================================== * Display error message and exit */ -void error(const char *msg) -{ +void error(const char *msg) { fprintf(stderr, "%s: %s\n", prog, msg); exit(1); } @@ -94,8 +93,7 @@ void error(const char *msg) * Compress input to output then close both files. */ -void gz_compress(FILE *in, gzFile out) -{ +void gz_compress(FILE *in, gzFile out) { char buf[BUFLEN]; int len; int err; @@ -128,8 +126,7 @@ void gz_compress(FILE *in, gzFile out) /* Try compressing the input file at once using mmap. Return Z_OK if * if success, Z_ERRNO otherwise. */ -int gz_compress_mmap(FILE *in, gzFile out) -{ +int gz_compress_mmap(FILE *in, gzFile out) { int len; int err; int ifd = fileno(in); @@ -161,8 +158,7 @@ int gz_compress_mmap(FILE *in, gzFile out) /* =========================================================================== * Uncompress input to output then close both files. */ -void gz_uncompress(gzFile in, FILE *out) -{ +void gz_uncompress(gzFile in, FILE *out) { char buf[BUFLENW]; int len; int err; @@ -186,10 +182,9 @@ void gz_uncompress(gzFile in, FILE *out) * Compress the given file: create a corresponding .gz file and remove the * original. */ -void file_compress(char *file, char *mode) -{ +void file_compress(char *file, char *mode) { char outfile[MAX_NAME_LEN]; - FILE *in; + FILE *in; gzFile out; if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) { @@ -218,11 +213,10 @@ void file_compress(char *file, char *mode) /* =========================================================================== * Uncompress the given file and remove the original. */ -void file_uncompress(char *file) -{ +void file_uncompress(char *file) { char buf[MAX_NAME_LEN]; char *infile, *outfile; - FILE *out; + FILE *out; gzFile in; size_t len = strlen(file); @@ -272,8 +266,7 @@ void file_uncompress(char *file) * -0 to -9 : compression level */ -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { int copyout = 0; int uncompr = 0; int i = 0; @@ -286,14 +279,14 @@ int main(int argc, char *argv[]) prog = argv[i]; bname = strrchr(argv[i], '/'); if (bname) - bname++; + bname++; else - bname = argv[i]; + bname = argv[i]; if (!strcmp(bname, "gunzip")) - uncompr = 1; + uncompr = 1; else if (!strcmp(bname, "zcat")) - copyout = uncompr = 1; + copyout = uncompr = 1; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-c") == 0) @@ -303,7 +296,7 @@ int main(int argc, char *argv[]) else if (strcmp(argv[i], "-A") == 0) type = ""; else if (argv[i][0] == '-' && (argv[i][1] == 'f' || argv[i][1] == 'h' || - argv[i][1] == 'R' || argv[i][1] == 'F' || argv[i][1] == 'T') && argv[i][2] == 0) + argv[i][1] == 'R' || argv[i][1] == 'F' || argv[i][1] == 'T') && argv[i][2] == 0) strategy = argv[i] + 1; else if (argv[i][0] == '-' && argv[i][1] >= '0' && argv[i][1] <= '9' && argv[i][2] == 0) level = argv[i] + 1; diff --git a/test/switchlevels.c b/test/switchlevels.c index 67bb1524a0..5c4770f8cd 100644 --- a/test/switchlevels.c +++ b/test/switchlevels.c @@ -13,8 +13,7 @@ #include #include -static int read_all(unsigned char *buf, size_t size) -{ +static int read_all(unsigned char *buf, size_t size) { for (size_t total_read = 0; total_read < size;) { size_t n_read = fread(buf + total_read, 1, size - total_read, stdin); if (ferror(stdin)) { @@ -30,8 +29,7 @@ static int read_all(unsigned char *buf, size_t size) return 0; } -static int write_all(unsigned char *buf, size_t size) -{ +static int write_all(unsigned char *buf, size_t size) { for (size_t total_written = 0; total_written < size;) { size_t n_written = fwrite(buf + total_written, 1, size - total_written, stdout); if (ferror(stdout)) { @@ -43,8 +41,7 @@ static int write_all(unsigned char *buf, size_t size) return 0; } -static int compress_chunk(PREFIX3(stream) *strm, int level, int size, int last) -{ +static int compress_chunk(PREFIX3(stream) *strm, int level, int size, int last) { int ret = 1; int err = PREFIX(deflateParams)(strm, level, Z_DEFAULT_STRATEGY); if (err != Z_OK) { @@ -87,8 +84,7 @@ static int compress_chunk(PREFIX3(stream) *strm, int level, int size, int last) * Usage: switchlevels level1 size1 [level2 size2 ...] */ -int main(int argc, char **argv) -{ +int main(int argc, char **argv) { int ret = EXIT_FAILURE; PREFIX3(stream) strm; memset(&strm, 0, sizeof(strm)); diff --git a/tools/maketrees.c b/tools/maketrees.c index 54ab4c09ee..d0e356cee9 100644 --- a/tools/maketrees.c +++ b/tools/maketrees.c @@ -121,7 +121,7 @@ static void gen_trees_header() { printf("%2u%s", dist_code[i], SEPARATOR(i, DIST_CODE_LEN-1, 20)); } - printf("const unsigned char ZLIB_INTERNAL zng_length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); + printf("const unsigned char ZLIB_INTERNAL zng_length_code[MAX_MATCH-MIN_MATCH+1] = {\n"); for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { printf("%2u%s", length_code[i], SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); } diff --git a/trees.c b/trees.c index bec889b0e9..a948b96c0f 100644 --- a/trees.c +++ b/trees.c @@ -423,7 +423,7 @@ static void scan_tree(deflate_state *s, ct_data *tree, int max_code) { int min_count = 4; /* min repeat count */ if (nextlen == 0) - max_count = 138, min_count = 3; + max_count = 138, min_count = 3; tree[max_code+1].Len = (uint16_t)0xffff; /* guard */ @@ -683,7 +683,7 @@ void ZLIB_INTERNAL zng_tr_flush_block(deflate_state *s, char *buf, unsigned long if (buf != NULL) { /* force stored block */ #else if (stored_len+4 <= opt_lenb && buf != NULL) { - /* 4: two words for the lengths */ + /* 4: two words for the lengths */ #endif /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. * Otherwise we can't have processed more than WSIZE input bytes since diff --git a/trees.h b/trees.h index a0273bf08b..6cdd1d55cb 100644 --- a/trees.h +++ b/trees.h @@ -102,7 +102,7 @@ const unsigned char ZLIB_INTERNAL zng_dist_code[DIST_CODE_LEN] = { 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 }; -const unsigned char ZLIB_INTERNAL zng_length_code[MAX_MATCH-MIN_MATCH+1]= { +const unsigned char ZLIB_INTERNAL zng_length_code[MAX_MATCH-MIN_MATCH+1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, diff --git a/uncompr.c b/uncompr.c index 9f0ac2a0cf..b2b6c14599 100644 --- a/uncompr.c +++ b/uncompr.c @@ -8,9 +8,9 @@ #define ZLIB_INTERNAL #include "zbuild.h" #ifdef ZLIB_COMPAT -# include "zlib.h" +# include "zlib.h" #else -# include "zlib-ng.h" +# include "zlib-ng.h" #endif /* =========================================================================== @@ -40,8 +40,7 @@ int ZEXPORT PREFIX(uncompress2)(unsigned char *dest, z_size_t *destLen, const un if (*destLen) { left = *destLen; *destLen = 0; - } - else { + } else { left = 1; dest = buf; } @@ -83,7 +82,6 @@ int ZEXPORT PREFIX(uncompress2)(unsigned char *dest, z_size_t *destLen, const un err; } -int ZEXPORT PREFIX(uncompress)(unsigned char *dest, z_size_t *destLen, const unsigned char *source, z_size_t sourceLen) -{ +int ZEXPORT PREFIX(uncompress)(unsigned char *dest, z_size_t *destLen, const unsigned char *source, z_size_t sourceLen) { return PREFIX(uncompress2)(dest, destLen, source, &sourceLen); } diff --git a/zendian.h b/zendian.h index 5921abbe1e..4236b13019 100644 --- a/zendian.h +++ b/zendian.h @@ -7,54 +7,54 @@ /* First check whether the compiler knows the target __BYTE_ORDER__. */ #if defined(__BYTE_ORDER__) -# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -# if !defined(LITTLE_ENDIAN) -# define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ -# endif -# if !defined(BYTE_ORDER) -# define BYTE_ORDER LITTLE_ENDIAN -# endif -# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -# if !defined(BIG_ENDIAN) -# define BIG_ENDIAN __ORDER_BIG_ENDIAN__ -# endif -# if !defined(BYTE_ORDER) -# define BYTE_ORDER BIG_ENDIAN +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# if !defined(LITTLE_ENDIAN) +# define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ +# endif +# if !defined(BYTE_ORDER) +# define BYTE_ORDER LITTLE_ENDIAN +# endif +# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# if !defined(BIG_ENDIAN) +# define BIG_ENDIAN __ORDER_BIG_ENDIAN__ +# endif +# if !defined(BYTE_ORDER) +# define BYTE_ORDER BIG_ENDIAN +# endif # endif -# endif #elif defined(__MINGW32__) -# include +# include #elif defined(WIN32) || defined(_WIN32) -# define LITTLE_ENDIAN 1234 -# define BIG_ENDIAN 4321 -# if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined (_M_ARM) || defined (_M_ARM64) -# define BYTE_ORDER LITTLE_ENDIAN -# else -# error Unknown endianness! -# endif +# define LITTLE_ENDIAN 1234 +# define BIG_ENDIAN 4321 +# if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined (_M_ARM) || defined (_M_ARM64) +# define BYTE_ORDER LITTLE_ENDIAN +# else +# error Unknown endianness! +# endif #elif defined(__linux__) -# include +# include #elif defined(__APPLE__) || defined(__arm__) || defined(__aarch64__) -# include +# include #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) -# include +# include #elif defined(__sun) || defined(sun) -# include -# if !defined(LITTLE_ENDIAN) -# define LITTLE_ENDIAN 4321 -# endif -# if !defined(BIG_ENDIAN) -# define BIG_ENDIAN 1234 -# endif -# if !defined(BYTE_ORDER) -# if defined(_BIG_ENDIAN) -# define BYTE_ORDER BIG_ENDIAN -# else -# define BYTE_ORDER LITTLE_ENDIAN +# include +# if !defined(LITTLE_ENDIAN) +# define LITTLE_ENDIAN 4321 +# endif +# if !defined(BIG_ENDIAN) +# define BIG_ENDIAN 1234 +# endif +# if !defined(BYTE_ORDER) +# if defined(_BIG_ENDIAN) +# define BYTE_ORDER BIG_ENDIAN +# else +# define BYTE_ORDER LITTLE_ENDIAN +# endif # endif -# endif #else -# include +# include #endif #endif diff --git a/zlib-ng.h b/zlib-ng.h index 0b91ec96f5..33033b4405 100644 --- a/zlib-ng.h +++ b/zlib-ng.h @@ -1939,9 +1939,9 @@ ZEXTERN ZEXPORT int zng_inflateResetKeep (zng_stream *); ZEXTERN ZEXPORT int zng_deflateResetKeep (zng_stream *); #ifdef WITH_GZFILEOP -# if (defined(WIN32) || defined(__MINGW__)) - ZEXTERN ZEXPORT gzFile zng_gzopen_w(const wchar_t *path, const char *mode); -# endif +# if (defined(WIN32) || defined(__MINGW__)) + ZEXTERN ZEXPORT gzFile zng_gzopen_w(const wchar_t *path, const char *mode); +# endif ZEXTERN ZEXPORTVA int zng_gzvprintf(gzFile file, const char *format, va_list va); #endif diff --git a/zlib.h b/zlib.h index 5b2f32b309..cc6632ac92 100644 --- a/zlib.h +++ b/zlib.h @@ -649,7 +649,7 @@ ZEXTERN int ZEXPORT deflateSetDictionary(z_stream *strm, not perform any compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateGetDictionary (z_stream *strm, unsigned char *dictionary, unsigned int *dictLength); +ZEXTERN int ZEXPORT deflateGetDictionary (z_stream *strm, unsigned char *dictionary, unsigned int *dictLength); /* Returns the sliding dictionary being maintained by deflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied diff --git a/zutil.c b/zutil.c index 223d0fcc6c..e2da87f9d5 100644 --- a/zutil.c +++ b/zutil.c @@ -11,7 +11,7 @@ # include "gzguts.h" #endif #ifndef UNALIGNED_OK -# include "malloc.h" +# include #endif const char * const zng_errmsg[10] = { @@ -28,22 +28,19 @@ const char * const zng_errmsg[10] = { }; const char zlibng_string[] = - " zlib-ng 1.9.9 forked from zlib 1.2.11 "; + " zlib-ng 1.9.9 forked from zlib 1.2.11 "; #ifdef ZLIB_COMPAT -const char * ZEXPORT zlibVersion(void) -{ +const char * ZEXPORT zlibVersion(void) { return ZLIB_VERSION; } #endif -const char * ZEXPORT zlibng_version(void) -{ +const char * ZEXPORT zlibng_version(void) { return ZLIBNG_VERSION; } -unsigned long ZEXPORT PREFIX(zlibCompileFlags)(void) -{ +unsigned long ZEXPORT PREFIX(zlibCompileFlags)(void) { unsigned long flags; flags = 0; @@ -93,15 +90,13 @@ unsigned long ZEXPORT PREFIX(zlibCompileFlags)(void) } #ifdef ZLIB_DEBUG -#include +# include # ifndef verbose # define verbose 0 # endif int ZLIB_INTERNAL z_verbose = verbose; -void ZLIB_INTERNAL z_error (m) - char *m; -{ +void ZLIB_INTERNAL z_error(char *m) { fprintf(stderr, "%s\n", m); exit(1); } @@ -110,15 +105,13 @@ void ZLIB_INTERNAL z_error (m) /* exported to allow conversion of error code to string for compress() and * uncompress() */ -const char * ZEXPORT PREFIX(zError)(int err) -{ +const char * ZEXPORT PREFIX(zError)(int err) { return ERR_MSG(err); } #ifndef MY_ZCALLOC /* Any system without a special alloc function */ -void ZLIB_INTERNAL *zng_calloc (void *opaque, unsigned items, unsigned size) -{ +void ZLIB_INTERNAL *zng_calloc(void *opaque, unsigned items, unsigned size) { (void)opaque; #ifndef UNALIGNED_OK return memalign(16, items * size); @@ -128,8 +121,7 @@ void ZLIB_INTERNAL *zng_calloc (void *opaque, unsigned items, unsigned size) #endif } -void ZLIB_INTERNAL zng_cfree (void *opaque, void *ptr) -{ +void ZLIB_INTERNAL zng_cfree(void *opaque, void *ptr) { (void)opaque; free(ptr); } diff --git a/zutil.h b/zutil.h index f9cf3ff9fe..be38ff4518 100644 --- a/zutil.h +++ b/zutil.h @@ -25,14 +25,14 @@ #include #include #ifdef ZLIB_COMPAT -# include "zlib.h" +# include "zlib.h" #else -# include "zlib-ng.h" +# include "zlib-ng.h" #endif typedef unsigned char uch; /* Included for compatibility with external code only */ typedef uint16_t ush; /* Included for compatibility with external code only */ -typedef unsigned long ulg; +typedef unsigned long ulg; extern const char * const zng_errmsg[10]; /* indexed by 2-zlib_error */ /* (size given to avoid silly warnings with Visual C++) */ @@ -116,7 +116,7 @@ extern const char * const zng_errmsg[10]; /* indexed by 2-zlib_error */ /* provide prototypes for these when building zlib without LFS */ #if !defined(WIN32) && !defined(__MSYS__) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) -# include "zbuild.h" /* For PREFIX() */ +# include "zbuild.h" /* For PREFIX() */ ZEXTERN uint32_t ZEXPORT PREFIX(adler32_combine64)(uint32_t, uint32_t, z_off_t); ZEXTERN uint32_t ZEXPORT PREFIX(crc32_combine64)(uint32_t, uint32_t, z_off_t); #endif @@ -141,22 +141,22 @@ extern const char * const zng_errmsg[10]; /* indexed by 2-zlib_error */ /* Diagnostic functions */ #ifdef ZLIB_DEBUG -# include - extern int ZLIB_INTERNAL z_verbose; - extern void ZLIB_INTERNAL z_error(char *m); -# define Assert(cond, msg) {if(!(cond)) z_error(msg);} -# define Trace(x) {if (z_verbose >= 0) fprintf x;} -# define Tracev(x) {if (z_verbose > 0) fprintf x;} -# define Tracevv(x) {if (z_verbose > 1) fprintf x;} -# define Tracec(c, x) {if (z_verbose > 0 && (c)) fprintf x;} -# define Tracecv(c, x) {if (z_verbose > 1 && (c)) fprintf x;} +# include + extern int ZLIB_INTERNAL z_verbose; + extern void ZLIB_INTERNAL z_error(char *m); +# define Assert(cond, msg) {if (!(cond)) z_error(msg);} +# define Trace(x) {if (z_verbose >= 0) fprintf x;} +# define Tracev(x) {if (z_verbose > 0) fprintf x;} +# define Tracevv(x) {if (z_verbose > 1) fprintf x;} +# define Tracec(c, x) {if (z_verbose > 0 && (c)) fprintf x;} +# define Tracecv(c, x) {if (z_verbose > 1 && (c)) fprintf x;} #else -# define Assert(cond, msg) -# define Trace(x) -# define Tracev(x) -# define Tracevv(x) -# define Tracec(c, x) -# define Tracecv(c, x) +# define Assert(cond, msg) +# define Trace(x) +# define Tracev(x) +# define Tracevv(x) +# define Tracec(c, x) +# define Tracecv(c, x) #endif void ZLIB_INTERNAL *zng_calloc(void *opaque, unsigned items, unsigned size); @@ -164,7 +164,7 @@ void ZLIB_INTERNAL zng_cfree(void *opaque, void *ptr); #define ZALLOC(strm, items, size) (*((strm)->zalloc))((strm)->opaque, (items), (size)) #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (void *)(addr)) -#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} +#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} /* Reverse the bytes in a value. Use compiler intrinsics when possible to take advantage of hardware implementations. */ @@ -215,41 +215,41 @@ void ZLIB_INTERNAL zng_cfree(void *opaque, void *ptr); /* Only enable likely/unlikely if the compiler is known to support it */ #if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__INTEL_COMPILER) || defined(__Clang__) -# define LIKELY_NULL(x) __builtin_expect((x) != 0, 0) -# define LIKELY(x) __builtin_expect(!!(x), 1) -# define UNLIKELY(x) __builtin_expect(!!(x), 0) -# define PREFETCH_L1(addr) __builtin_prefetch(addr, 0, 3) -# define PREFETCH_L2(addr) __builtin_prefetch(addr, 0, 2) -# define PREFETCH_RW(addr) __builtin_prefetch(addr, 1, 2) +# define LIKELY_NULL(x) __builtin_expect((x) != 0, 0) +# define LIKELY(x) __builtin_expect(!!(x), 1) +# define UNLIKELY(x) __builtin_expect(!!(x), 0) +# define PREFETCH_L1(addr) __builtin_prefetch(addr, 0, 3) +# define PREFETCH_L2(addr) __builtin_prefetch(addr, 0, 2) +# define PREFETCH_RW(addr) __builtin_prefetch(addr, 1, 2) #elif defined(__WIN__) -# include -# define LIKELY_NULL(x) x -# define LIKELY(x) x -# define UNLIKELY(x) x -# define PREFETCH_L1(addr) _mm_prefetch((char *) addr, _MM_HINT_T0) -# define PREFETCH_L2(addr) _mm_prefetch((char *) addr, _MM_HINT_T1) -# define PREFETCH_RW(addr) _mm_prefetch((char *) addr, _MM_HINT_T1) +# include +# define LIKELY_NULL(x) x +# define LIKELY(x) x +# define UNLIKELY(x) x +# define PREFETCH_L1(addr) _mm_prefetch((char *) addr, _MM_HINT_T0) +# define PREFETCH_L2(addr) _mm_prefetch((char *) addr, _MM_HINT_T1) +# define PREFETCH_RW(addr) _mm_prefetch((char *) addr, _MM_HINT_T1) #else -# define LIKELY_NULL(x) x -# define LIKELY(x) x -# define UNLIKELY(x) x -# define PREFETCH_L1(addr) addr -# define PREFETCH_L2(addr) addr -# define PREFETCH_RW(addr) addr +# define LIKELY_NULL(x) x +# define LIKELY(x) x +# define UNLIKELY(x) x +# define PREFETCH_L1(addr) addr +# define PREFETCH_L2(addr) addr +# define PREFETCH_RW(addr) addr #endif /* (un)likely */ #if defined(_MSC_VER) -#define ALIGNED_(x) __declspec(align(x)) +# define ALIGNED_(x) __declspec(align(x)) #else -#if defined(__GNUC__) -#define ALIGNED_(x) __attribute__ ((aligned(x))) -#endif +# if defined(__GNUC__) +# define ALIGNED_(x) __attribute__ ((aligned(x))) +# endif #endif #if defined(X86_CPUID) -# include "arch/x86/x86.h" +# include "arch/x86/x86.h" #elif defined(ARM_GETAUXVAL) -# include "arch/arm/arm.h" +# include "arch/arm/arm.h" #endif #endif /* ZUTIL_H_ */