From 0d0684ac0fea8eef2029af0ec939143bdfaf290c Mon Sep 17 00:00:00 2001 From: Mathis Rosenhauer Date: Fri, 13 Oct 2017 13:48:30 +0200 Subject: [PATCH] Avoid declaration after statement --- src/decode.c | 29 +++++++++++++++++------------ src/encode.c | 3 ++- src/sz_compat.c | 35 ++++++++++++++++++++++------------- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/decode.c b/src/decode.c index 11dfd94..160d4c3 100644 --- a/src/decode.c +++ b/src/decode.c @@ -94,10 +94,11 @@ xmax = state->xmax; \ \ for (bp = state->flush_start; bp < flush_end; bp++) { \ + uint32_t mask; \ d = *bp; \ half_d = (d >> 1) + (d & 1); \ /*in this case: data >= med == data & med */ \ - uint32_t mask = (data & med)?xmax:0; \ + mask = (data & med)?xmax:0; \ \ /*in this case: xmax - data == xmax ^ data */ \ if (half_d <= (mask ^ (uint32_t)data)) { \ @@ -303,21 +304,23 @@ static inline uint32_t direct_get_fs(struct aec_stream *strm) state->bitp = 56; } + { #ifndef __has_builtin #define __has_builtin(x) 0 /* Compatibility with non-clang compilers. */ #endif #if HAVE_DECL___BUILTIN_CLZLL || __has_builtin(__builtin_clzll) - int i = 63 - __builtin_clzll(state->acc); + int i = 63 - __builtin_clzll(state->acc); #elif HAVE_BSR64 - unsigned long i; - _BitScanReverse64(&i, state->acc); + unsigned long i; + _BitScanReverse64(&i, state->acc); #else - int i = state->bitp - 1; - while ((state->acc & (UINT64_C(1) << i)) == 0) - i--; + int i = state->bitp - 1; + while ((state->acc & (UINT64_C(1) << i)) == 0) + i--; #endif - fs += state->bitp - i - 1; - state->bitp = i; + fs += state->bitp - i - 1; + state->bitp = i; + } return fs; } @@ -676,6 +679,7 @@ static void create_se_table(int *table) int aec_decode_init(struct aec_stream *strm) { struct internal_state *state; + int modi; if (strm->bits_per_sample > 32 || strm->bits_per_sample == 0) return AEC_CONF_ERROR; @@ -745,7 +749,7 @@ int aec_decode_init(struct aec_stream *strm) state->in_blklen = (strm->block_size * strm->bits_per_sample + state->id_len) / 8 + 16; - int modi = 1UL << state->id_len; + modi = 1UL << state->id_len; state->id_table = malloc(modi * sizeof(int (*)(struct aec_stream *))); if (state->id_table == NULL) return AEC_MEM_ERROR; @@ -791,11 +795,12 @@ int aec_decode(struct aec_stream *strm, int flush) of the states are called. Inspired by zlib. */ + struct internal_state *state = strm->state; + int status; + strm->total_in += strm->avail_in; strm->total_out += strm->avail_out; - struct internal_state *state = strm->state; - int status; do { status = state->mode(strm); } while (status == M_CONTINUE); diff --git a/src/encode.c b/src/encode.c index 26838b4..cbaf8af 100644 --- a/src/encode.c +++ b/src/encode.c @@ -580,11 +580,12 @@ static int m_select_code_option(struct aec_stream *strm) struct internal_state *state = strm->state; uint32_t split_len; + uint32_t se_len; if (state->id_len > 1) split_len = assess_splitting_option(strm); else split_len = UINT32_MAX; - uint32_t se_len = assess_se_option(strm); + se_len = assess_se_option(strm); if (split_len < state->uncomp_len) { if (split_len < se_len) diff --git a/src/sz_compat.c b/src/sz_compat.c index c64882e..f852ed2 100644 --- a/src/sz_compat.c +++ b/src/sz_compat.c @@ -99,7 +99,15 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen, SZ_com_t *param) { struct aec_stream strm; + void *buf = 0; + void *padbuf = 0; int status; + int interleave; + int pixel_size; + int aec_status; + size_t scanlines; + size_t padbuf_size; + size_t padding_size; strm.block_size = param->pixels_per_block; strm.rsi = (param->pixels_per_scanline + param->pixels_per_block - 1) @@ -107,10 +115,8 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen, strm.flags = AEC_NOT_ENFORCE | convert_options(param->options_mask); strm.avail_out = *destLen; strm.next_out = dest; - void *buf = 0; - void *padbuf = 0; - int interleave = param->bits_per_pixel == 32 || param->bits_per_pixel == 64; + interleave = param->bits_per_pixel == 32 || param->bits_per_pixel == 64; if (interleave) { strm.bits_per_sample = 8; buf = malloc(sourceLen); @@ -124,18 +130,18 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen, buf = (void *)source; } - int pixel_size = bits_to_bytes(strm.bits_per_sample); + pixel_size = bits_to_bytes(strm.bits_per_sample); - size_t scanlines = (sourceLen / pixel_size + param->pixels_per_scanline - 1) + scanlines = (sourceLen / pixel_size + param->pixels_per_scanline - 1) / param->pixels_per_scanline; - size_t padbuf_size = strm.rsi * strm.block_size * pixel_size * scanlines; + padbuf_size = strm.rsi * strm.block_size * pixel_size * scanlines; padbuf = malloc(padbuf_size); if (padbuf == NULL) { status = SZ_MEM_ERROR; goto CLEANUP; } - size_t padding_size = + padding_size = (strm.rsi * strm.block_size - param->pixels_per_scanline) * pixel_size; @@ -146,7 +152,7 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen, strm.next_in = padbuf; strm.avail_in = padbuf_size; - int aec_status = aec_buffer_encode(&strm); + aec_status = aec_buffer_encode(&strm); if (aec_status == AEC_STREAM_ERROR) status = SZ_OUTBUFF_FULL; else @@ -166,7 +172,12 @@ int SZ_BufftoBuffDecompress(void *dest, size_t *destLen, SZ_com_t *param) { struct aec_stream strm; + void *buf = 0; int status; + int pad_scanline; + int deinterleave; + int extra_buffer; + int pixel_size; size_t total_out; size_t scanlines; @@ -176,13 +187,11 @@ int SZ_BufftoBuffDecompress(void *dest, size_t *destLen, strm.flags = convert_options(param->options_mask); strm.avail_in = sourceLen; strm.next_in = source; - void *buf = 0; - int pad_scanline = param->pixels_per_scanline % param->pixels_per_block; - int deinterleave = (param->bits_per_pixel == 32 + pad_scanline = param->pixels_per_scanline % param->pixels_per_block; + deinterleave = (param->bits_per_pixel == 32 || param->bits_per_pixel == 64); - int extra_buffer = pad_scanline || deinterleave; - int pixel_size; + extra_buffer = pad_scanline || deinterleave; if (deinterleave) strm.bits_per_sample = 8; -- 2.7.4