Commit 4add047d authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

Limit scope

parent 6cd141a9
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src tests SUBDIRS = src tests
EXTRA_DIST = doc/patent.txt CMakeLists.txt cmake/config.h.in \ EXTRA_DIST = doc/patent.txt CMakeLists.txt cmake/config.h.in \
cmake/macros.cmake README.md README.SZIP CHANGELOG.am Copyright.txt data cmake/macros.cmake README.md README.SZIP CHANGELOG.md Copyright.txt data
sampledata = 121B2TestData sampledata = 121B2TestData
sampledata_url = http://cwe.ccsds.org/sls/docs/SLS-DC/BB121B2TestData/$(sampledata).zip sampledata_url = http://cwe.ccsds.org/sls/docs/SLS-DC/BB121B2TestData/$(sampledata).zip
......
...@@ -213,10 +213,9 @@ static inline uint32_t direct_get(struct aec_stream *strm, int n) ...@@ -213,10 +213,9 @@ static inline uint32_t direct_get(struct aec_stream *strm, int n)
*/ */
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
int b;
if (state->bitp < n) if (state->bitp < n)
{ {
b = (63 - state->bitp) >> 3; int b = (63 - state->bitp) >> 3;
if (b == 6) { if (b == 6) {
state->acc = (state->acc << 48) state->acc = (state->acc << 48)
| ((uint64_t)strm->next_in[0] << 40) | ((uint64_t)strm->next_in[0] << 40)
...@@ -279,11 +278,6 @@ static inline uint32_t direct_get_fs(struct aec_stream *strm) ...@@ -279,11 +278,6 @@ static inline uint32_t direct_get_fs(struct aec_stream *strm)
*/ */
uint32_t fs = 0; uint32_t fs = 0;
#if HAVE_BSR64
unsigned long i;
#else
int i;
#endif
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
if (state->bitp) if (state->bitp)
...@@ -313,11 +307,12 @@ static inline uint32_t direct_get_fs(struct aec_stream *strm) ...@@ -313,11 +307,12 @@ static inline uint32_t direct_get_fs(struct aec_stream *strm)
#define __has_builtin(x) 0 /* Compatibility with non-clang compilers. */ #define __has_builtin(x) 0 /* Compatibility with non-clang compilers. */
#endif #endif
#if HAVE_DECL___BUILTIN_CLZLL || __has_builtin(__builtin_clzll) #if HAVE_DECL___BUILTIN_CLZLL || __has_builtin(__builtin_clzll)
i = 63 - __builtin_clzll(state->acc); int i = 63 - __builtin_clzll(state->acc);
#elif HAVE_BSR64 #elif HAVE_BSR64
unsigned long i;
_BitScanReverse64(&i, state->acc); _BitScanReverse64(&i, state->acc);
#else #else
i = state->bitp - 1; int i = state->bitp - 1;
while ((state->acc & (UINT64_C(1) << i)) == 0) while ((state->acc & (UINT64_C(1) << i)) == 0)
i--; i--;
#endif #endif
...@@ -437,7 +432,7 @@ static int m_split_output(struct aec_stream *strm) ...@@ -437,7 +432,7 @@ static int m_split_output(struct aec_stream *strm)
state->rsip++; state->rsip++;
strm->avail_out -= state->bytes_per_sample; strm->avail_out -= state->bytes_per_sample;
bits_drop(strm, k); bits_drop(strm, k);
} while(++state->i < state->n); } while(++state->sample_counter < state->encoded_block_size);
state->mode = m_next_cds; state->mode = m_next_cds;
return M_CONTINUE; return M_CONTINUE;
...@@ -451,11 +446,11 @@ static int m_split_fs(struct aec_stream *strm) ...@@ -451,11 +446,11 @@ static int m_split_fs(struct aec_stream *strm)
do { do {
if (fs_ask(strm) == 0) if (fs_ask(strm) == 0)
return M_EXIT; return M_EXIT;
state->rsip[state->i] = state->fs << k; state->rsip[state->sample_counter] = state->fs << k;
fs_drop(strm); fs_drop(strm);
} while(++state->i < state->n); } while(++state->sample_counter < state->encoded_block_size);
state->i = 0; state->sample_counter = 0;
state->mode = m_split_output; state->mode = m_split_output;
return M_CONTINUE; return M_CONTINUE;
...@@ -463,26 +458,23 @@ static int m_split_fs(struct aec_stream *strm) ...@@ -463,26 +458,23 @@ static int m_split_fs(struct aec_stream *strm)
static int m_split(struct aec_stream *strm) static int m_split(struct aec_stream *strm)
{ {
size_t i;
size_t binary_part;
int k;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
if (BUFFERSPACE(strm)) { if (BUFFERSPACE(strm)) {
k = state->id - 1; int k = state->id - 1;
binary_part = (k * state->encoded_block_size) / 8 + 9; size_t binary_part = (k * state->encoded_block_size) / 8 + 9;
if (state->ref) if (state->ref)
*state->rsip++ = direct_get(strm, strm->bits_per_sample); *state->rsip++ = direct_get(strm, strm->bits_per_sample);
for (i = 0; i < state->encoded_block_size; i++) for (size_t i = 0; i < state->encoded_block_size; i++)
state->rsip[i] = direct_get_fs(strm) << k; state->rsip[i] = direct_get_fs(strm) << k;
if (k) { if (k) {
if (strm->avail_in < binary_part) if (strm->avail_in < binary_part)
return M_ERROR; return M_ERROR;
for (i = 0; i < state->encoded_block_size; i++) for (size_t i = 0; i < state->encoded_block_size; i++)
*state->rsip++ += direct_get(strm, k); *state->rsip++ += direct_get(strm, k);
} else { } else {
state->rsip += state->encoded_block_size; state->rsip += state->encoded_block_size;
...@@ -493,8 +485,7 @@ static int m_split(struct aec_stream *strm) ...@@ -493,8 +485,7 @@ static int m_split(struct aec_stream *strm)
} else { } else {
if (state->ref && (copysample(strm) == 0)) if (state->ref && (copysample(strm) == 0))
return M_EXIT; return M_EXIT;
state->n = state->encoded_block_size; state->sample_counter = 0;
state->i = 0;
state->mode = m_split_fs; state->mode = m_split_fs;
} }
return M_CONTINUE; return M_CONTINUE;
...@@ -508,7 +499,7 @@ static int m_zero_output(struct aec_stream *strm) ...@@ -508,7 +499,7 @@ static int m_zero_output(struct aec_stream *strm)
if (strm->avail_out < state->bytes_per_sample) if (strm->avail_out < state->bytes_per_sample)
return M_EXIT; return M_EXIT;
put_sample(strm, 0); put_sample(strm, 0);
} while(--state->i); } while(--state->sample_counter);
state->mode = m_next_cds; state->mode = m_next_cds;
return M_CONTINUE; return M_CONTINUE;
...@@ -516,46 +507,48 @@ static int m_zero_output(struct aec_stream *strm) ...@@ -516,46 +507,48 @@ static int m_zero_output(struct aec_stream *strm)
static int m_zero_block(struct aec_stream *strm) static int m_zero_block(struct aec_stream *strm)
{ {
uint32_t i, zero_blocks, b, zero_bytes;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
uint32_t zero_blocks;
uint32_t zero_samples;
uint32_t zero_bytes;
if (fs_ask(strm) == 0) if (fs_ask(strm) == 0)
return M_EXIT; return M_EXIT;
zero_blocks = state->fs + 1; zero_blocks = state->fs + 1;
fs_drop(strm); fs_drop(strm);
if (zero_blocks == ROS) { if (zero_blocks == ROS) {
b = (int)RSI_USED_SIZE(state) / strm->block_size; int b = (int)RSI_USED_SIZE(state) / strm->block_size;
zero_blocks = MIN(strm->rsi - b, 64 - (b % 64)); zero_blocks = MIN(strm->rsi - b, 64 - (b % 64));
} else if (zero_blocks > ROS) { } else if (zero_blocks > ROS) {
zero_blocks--; zero_blocks--;
} }
i = zero_blocks * strm->block_size - state->ref; zero_samples = zero_blocks * strm->block_size - state->ref;
zero_bytes = i * state->bytes_per_sample; if (state->rsi_size - RSI_USED_SIZE(state) < zero_samples)
if (state->rsi_size - RSI_USED_SIZE(state) < i)
return M_ERROR; return M_ERROR;
zero_bytes = zero_samples * state->bytes_per_sample;
if (strm->avail_out >= zero_bytes) { if (strm->avail_out >= zero_bytes) {
memset(state->rsip, 0, i * sizeof(uint32_t)); memset(state->rsip, 0, zero_samples * sizeof(uint32_t));
state->rsip += i; state->rsip += zero_samples;
strm->avail_out -= zero_bytes; strm->avail_out -= zero_bytes;
state->mode = m_next_cds; state->mode = m_next_cds;
return M_CONTINUE; } else {
state->sample_counter = zero_samples;
state->mode = m_zero_output;
} }
state->i = i;
state->mode = m_zero_output;
return M_CONTINUE; return M_CONTINUE;
} }
static int m_se_decode(struct aec_stream *strm) static int m_se_decode(struct aec_stream *strm)
{ {
int32_t m, d1;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
while(state->i < strm->block_size) { while(state->sample_counter < strm->block_size) {
int32_t m;
int32_t d1;
if (fs_ask(strm) == 0) if (fs_ask(strm) == 0)
return M_EXIT; return M_EXIT;
m = state->fs; m = state->fs;
...@@ -563,17 +556,17 @@ static int m_se_decode(struct aec_stream *strm) ...@@ -563,17 +556,17 @@ static int m_se_decode(struct aec_stream *strm)
return M_ERROR; return M_ERROR;
d1 = m - state->se_table[2 * m + 1]; d1 = m - state->se_table[2 * m + 1];
if ((state->i & 1) == 0) { if ((state->sample_counter & 1) == 0) {
if (strm->avail_out < state->bytes_per_sample) if (strm->avail_out < state->bytes_per_sample)
return M_EXIT; return M_EXIT;
put_sample(strm, state->se_table[2 * m] - d1); put_sample(strm, state->se_table[2 * m] - d1);
state->i++; state->sample_counter++;
} }
if (strm->avail_out < state->bytes_per_sample) if (strm->avail_out < state->bytes_per_sample)
return M_EXIT; return M_EXIT;
put_sample(strm, d1); put_sample(strm, d1);
state->i++; state->sample_counter++;
fs_drop(strm); fs_drop(strm);
} }
...@@ -583,16 +576,14 @@ static int m_se_decode(struct aec_stream *strm) ...@@ -583,16 +576,14 @@ static int m_se_decode(struct aec_stream *strm)
static int m_se(struct aec_stream *strm) static int m_se(struct aec_stream *strm)
{ {
uint32_t i;
uint32_t m;
int32_t d1;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
if (BUFFERSPACE(strm)) { if (BUFFERSPACE(strm)) {
i = state->ref; uint32_t i = state->ref;
while (i < strm->block_size) { while (i < strm->block_size) {
m = direct_get_fs(strm); uint32_t m = direct_get_fs(strm);
int32_t d1;
if (m > SE_TABLE_SIZE) if (m > SE_TABLE_SIZE)
return M_ERROR; return M_ERROR;
...@@ -609,7 +600,7 @@ static int m_se(struct aec_stream *strm) ...@@ -609,7 +600,7 @@ static int m_se(struct aec_stream *strm)
state->mode = m_next_cds; state->mode = m_next_cds;
} else { } else {
state->mode = m_se_decode; state->mode = m_se_decode;
state->i = state->ref; state->sample_counter = state->ref;
} }
return M_CONTINUE; return M_CONTINUE;
} }
...@@ -621,12 +612,10 @@ static int m_low_entropy_ref(struct aec_stream *strm) ...@@ -621,12 +612,10 @@ static int m_low_entropy_ref(struct aec_stream *strm)
if (state->ref && copysample(strm) == 0) if (state->ref && copysample(strm) == 0)
return M_EXIT; return M_EXIT;
if (state->id == 1) { if (state->id == 1)
state->mode = m_se; state->mode = m_se;
return M_CONTINUE; else
} state->mode = m_zero_block;
state->mode = m_zero_block;
return M_CONTINUE; return M_CONTINUE;
} }
...@@ -649,7 +638,7 @@ static int m_uncomp_copy(struct aec_stream *strm) ...@@ -649,7 +638,7 @@ static int m_uncomp_copy(struct aec_stream *strm)
do { do {
if (copysample(strm) == 0) if (copysample(strm) == 0)
return M_EXIT; return M_EXIT;
} while(--state->i); } while(--state->sample_counter);
state->mode = m_next_cds; state->mode = m_next_cds;
return M_CONTINUE; return M_CONTINUE;
...@@ -657,16 +646,15 @@ static int m_uncomp_copy(struct aec_stream *strm) ...@@ -657,16 +646,15 @@ static int m_uncomp_copy(struct aec_stream *strm)
static int m_uncomp(struct aec_stream *strm) static int m_uncomp(struct aec_stream *strm)
{ {
size_t i;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
if (BUFFERSPACE(strm)) { if (BUFFERSPACE(strm)) {
for (i = 0; i < strm->block_size; i++) for (size_t i = 0; i < strm->block_size; i++)
*state->rsip++ = direct_get(strm, strm->bits_per_sample); *state->rsip++ = direct_get(strm, strm->bits_per_sample);
strm->avail_out -= state->out_blklen; strm->avail_out -= state->out_blklen;
state->mode = m_next_cds; state->mode = m_next_cds;
} else { } else {
state->i = strm->block_size; state->sample_counter = strm->block_size;
state->mode = m_uncomp_copy; state->mode = m_uncomp_copy;
} }
return M_CONTINUE; return M_CONTINUE;
...@@ -674,12 +662,10 @@ static int m_uncomp(struct aec_stream *strm) ...@@ -674,12 +662,10 @@ static int m_uncomp(struct aec_stream *strm)
static void create_se_table(int *table) static void create_se_table(int *table)
{ {
int i, j, k, ms; int k = 0;
for (int i = 0; i < 13; i++) {
k = 0; int ms = k;
for (i = 0; i < 13; i++) { for (int j = 0; j <= i; j++) {
ms = k;
for (j = 0; j <= i; j++) {
table[2 * k] = i; table[2 * k] = i;
table[2 * k + 1] = ms; table[2 * k + 1] = ms;
k++; k++;
...@@ -689,7 +675,6 @@ static void create_se_table(int *table) ...@@ -689,7 +675,6 @@ static void create_se_table(int *table)
int aec_decode_init(struct aec_stream *strm) int aec_decode_init(struct aec_stream *strm)
{ {
int i, modi;
struct internal_state *state; struct internal_state *state;
if (strm->bits_per_sample > 32 || strm->bits_per_sample == 0) if (strm->bits_per_sample > 32 || strm->bits_per_sample == 0)
...@@ -760,13 +745,13 @@ int aec_decode_init(struct aec_stream *strm) ...@@ -760,13 +745,13 @@ int aec_decode_init(struct aec_stream *strm)
state->in_blklen = (strm->block_size * strm->bits_per_sample state->in_blklen = (strm->block_size * strm->bits_per_sample
+ state->id_len) / 8 + 16; + state->id_len) / 8 + 16;
modi = 1UL << state->id_len; int modi = 1UL << state->id_len;
state->id_table = malloc(modi * sizeof(int (*)(struct aec_stream *))); state->id_table = malloc(modi * sizeof(int (*)(struct aec_stream *)));
if (state->id_table == NULL) if (state->id_table == NULL)
return AEC_MEM_ERROR; return AEC_MEM_ERROR;
state->id_table[0] = m_low_entropy; state->id_table[0] = m_low_entropy;
for (i = 1; i < modi - 1; i++) { for (int i = 1; i < modi - 1; i++) {
state->id_table[i] = m_split; state->id_table[i] = m_split;
} }
state->id_table[modi - 1] = m_uncomp; state->id_table[modi - 1] = m_uncomp;
...@@ -806,12 +791,11 @@ int aec_decode(struct aec_stream *strm, int flush) ...@@ -806,12 +791,11 @@ int aec_decode(struct aec_stream *strm, int flush)
of the states are called. Inspired by zlib. of the states are called. Inspired by zlib.
*/ */
struct internal_state *state = strm->state;
int status;
strm->total_in += strm->avail_in; strm->total_in += strm->avail_in;
strm->total_out += strm->avail_out; strm->total_out += strm->avail_out;
struct internal_state *state = strm->state;
int status;
do { do {
status = state->mode(strm); status = state->mode(strm);
} while (status == M_CONTINUE); } while (status == M_CONTINUE);
...@@ -843,9 +827,7 @@ int aec_decode_end(struct aec_stream *strm) ...@@ -843,9 +827,7 @@ int aec_decode_end(struct aec_stream *strm)
int aec_buffer_decode(struct aec_stream *strm) int aec_buffer_decode(struct aec_stream *strm)
{ {
int status; int status = aec_decode_init(strm);
status = aec_decode_init(strm);
if (status != AEC_OK) if (status != AEC_OK)
return status; return status;
......
...@@ -97,8 +97,7 @@ struct internal_state { ...@@ -97,8 +97,7 @@ struct internal_state {
/* length of output block in bytes */ /* length of output block in bytes */
uint32_t out_blklen; uint32_t out_blklen;
/* counter for samples */ uint32_t sample_counter;
uint32_t n, i;
/* accumulator for currently used bit sequence */ /* accumulator for currently used bit sequence */
uint64_t acc; uint64_t acc;
......
...@@ -117,15 +117,12 @@ static inline void copy64(uint8_t *dst, uint64_t src) ...@@ -117,15 +117,12 @@ static inline void copy64(uint8_t *dst, uint64_t src)
static inline void emitblock_fs(struct aec_stream *strm, int k, int ref) static inline void emitblock_fs(struct aec_stream *strm, int k, int ref)
{ {
size_t i;
uint32_t used; /* used bits in 64 bit accumulator */
uint64_t acc; /* accumulator */
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
acc = (uint64_t)*state->cds << 56; uint64_t acc = (uint64_t)*state->cds << 56;
used = 7 - state->bits; uint32_t used = 7 - state->bits; /* used bits in 64 bit accumulator */
for (i = ref; i < strm->block_size; i++) { for (size_t i = ref; i < strm->block_size; i++) {
used += (state->block[i] >> k) + 1; used += (state->block[i] >> k) + 1;
while (used > 63) { while (used > 63) {
copy64(state->cds, acc); copy64(state->cds, acc);
...@@ -147,16 +144,14 @@ static inline void emitblock(struct aec_stream *strm, int k, int ref) ...@@ -147,16 +144,14 @@ static inline void emitblock(struct aec_stream *strm, int k, int ref)
Emit the k LSB of a whole block of input data. Emit the k LSB of a whole block of input data.
*/ */
uint64_t a;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
uint32_t *in = state->block + ref; uint32_t *in = state->block + ref;
uint32_t *in_end = state->block + strm->block_size; uint32_t *in_end = state->block + strm->block_size;
uint64_t mask = (UINT64_C(1) << k) - 1; uint64_t mask = (UINT64_C(1) << k) - 1;
uint8_t *o = state->cds; uint8_t *o = state->cds;
uint64_t a = *o;
int p = state->bits; int p = state->bits;
a = *o;
while(in < in_end) { while(in < in_end) {
a <<= 56; a <<= 56;
p = (p % 8) + 56; p = (p % 8) + 56;
...@@ -247,12 +242,11 @@ static void preprocess_unsigned(struct aec_stream *strm) ...@@ -247,12 +242,11 @@ static void preprocess_unsigned(struct aec_stream *strm)
uint32_t *restrict d = state->data_pp; uint32_t *restrict d = state->data_pp;
uint32_t xmax = state->xmax; uint32_t xmax = state->xmax;
uint32_t rsi = strm->rsi * strm->block_size - 1; uint32_t rsi = strm->rsi * strm->block_size - 1;
size_t i;
state->ref = 1; state->ref = 1;
state->ref_sample = x[0]; state->ref_sample = x[0];
d[0] = 0; d[0] = 0;
for (i = 0; i < rsi; i++) { for (size_t i = 0; i < rsi; i++) {
if (x[i + 1] >= x[i]) { if (x[i + 1] >= x[i]) {
D = x[i + 1] - x[i]; D = x[i + 1] - x[i];
if (D <= x[i]) if (D <= x[i])
...@@ -284,14 +278,13 @@ static void preprocess_signed(struct aec_stream *strm) ...@@ -284,14 +278,13 @@ static void preprocess_signed(struct aec_stream *strm)
int32_t xmin = (int32_t)state->xmin; int32_t xmin = (int32_t)state->xmin;
uint32_t rsi = strm->rsi * strm->block_size - 1; uint32_t rsi = strm->rsi * strm->block_size - 1;
uint32_t m = UINT64_C(1) << (strm->bits_per_sample - 1); uint32_t m = UINT64_C(1) << (strm->bits_per_sample - 1);
size_t i;
state->ref = 1; state->ref = 1;
state->ref_sample = x[0]; state->ref_sample = x[0];
d[0] = 0; d[0] = 0;
x[0] = (x[0] ^ m) - m; x[0] = (x[0] ^ m) - m;
for (i = 0; i < rsi; i++) { for (size_t i = 0; i < rsi; i++) {
x[i + 1] = (x[i + 1] ^ m) - m; x[i + 1] = (x[i + 1] ^ m) - m;
if (x[i + 1] < x[i]) { if (x[i + 1] < x[i]) {
D = (uint32_t)(x[i] - x[i + 1]); D = (uint32_t)(x[i] - x[i + 1]);
...@@ -316,11 +309,10 @@ static inline uint64_t block_fs(struct aec_stream *strm, int k) ...@@ -316,11 +309,10 @@ static inline uint64_t block_fs(struct aec_stream *strm, int k)
Sum FS of all samples in block for given splitting position. Sum FS of all samples in block for given splitting position.
*/ */
size_t i;
uint64_t fs = 0;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
uint64_t fs = 0;
for (i = 0; i < strm->block_size; i++) for (size_t i = 0; i < strm->block_size; i++)
fs += (uint64_t)(state->block[i] >> k); fs += (uint64_t)(state->block[i] >> k);
return fs; return fs;
...@@ -353,26 +345,29 @@ static uint32_t assess_splitting_option(struct aec_stream *strm) ...@@ -353,26 +345,29 @@ static uint32_t assess_splitting_option(struct aec_stream *strm)
analogue check can be done for decreasing k. analogue check can be done for decreasing k.
*/ */
int k;
int k_min;
int this_bs; /* Block size of current block */
int no_turn; /* 1 if we shouldn't reverse */
int dir; /* Direction, 1 means increasing k, 0 decreasing k */
uint64_t len; /* CDS length for current k */
uint64_t len_min; /* CDS length minimum so far */
uint64_t fs_len; /* Length of FS part (not including 1s) */
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
this_bs = strm->block_size - state->ref; /* Block size of current block */
len_min = UINT64_MAX; int this_bs = strm->block_size - state->ref;
k = k_min = state->k;
no_turn = k == 0; /* CDS length minimum so far */
dir = 1; uint64_t len_min = UINT64_MAX;
int k = state->k;
int k_min = k;
/* 1 if we shouldn't reverse */
int no_turn = (k == 0);
/* Direction, 1 means increasing k, 0 decreasing k */
int dir = 1;
for (;;) { for (;;) {
fs_len = block_fs(strm, k); /* Length of FS part (not including 1s) */
len = fs_len + this_bs * (k + 1); uint64_t fs_len = block_fs(strm, k);
/* CDS length for current k */
uint64_t len = fs_len + this_bs * (k + 1);
if (len < len_min) { if (len < len_min) {
if (len_min < UINT64_MAX) if (len_min < UINT64_MAX)
...@@ -417,15 +412,12 @@ static uint32_t assess_se_option(struct aec_stream *strm) ...@@ -417,15 +412,12 @@ static uint32_t assess_se_option(struct aec_stream *strm)
If length is above limit just return UINT32_MAX. If length is above limit just return UINT32_MAX.
*/ */
size_t i;
uint64_t len, d;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
uint32_t *block = state->block; uint32_t *block = state->block;
uint64_t len = 1;
len = 1; for (size_t i = 0; i < strm->block_size; i += 2) {
uint64_t d = (uint64_t)block[i] + (uint64_t)block[i + 1];
for (i = 0; i < strm->block_size; i += 2) {
d = (uint64_t)block[i] + (uint64_t)block[i + 1];
len += d * (d + 1) / 2 + block[i + 1] + 1; len += d * (d + 1) / 2 + block[i + 1] + 1;
if (len > state->uncomp_len) if (len > state->uncomp_len)
return UINT32_MAX; return UINT32_MAX;
...@@ -493,7 +485,6 @@ static int m_flush_block(struct aec_stream *strm) ...@@ -493,7 +485,6 @@ static int m_flush_block(struct aec_stream *strm)
Fall back to slow flushing if in buffered mode. Fall back to slow flushing if in buffered mode.
*/ */
int n;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
#ifdef ENABLE_RSI_PADDING #ifdef ENABLE_RSI_PADDING
...@@ -505,7 +496,7 @@ static int m_flush_block(struct aec_stream *strm) ...@@ -505,7 +496,7 @@ static int m_flush_block(struct aec_stream *strm)
#endif #endif
if (state->direct_out) { if (state->direct_out) {
n = (int)(state->cds - strm->next_out); int n = (int)(state->cds - strm->next_out);
strm->next_out += n; strm->next_out += n;
strm->avail_out -= n; strm->avail_out -= n;
state->mode = m_get_block; state->mode = m_get_block;
...@@ -546,16 +537,14 @@ static int m_encode_uncomp(struct aec_stream *strm) ...@@ -546,16 +537,14 @@ static int m_encode_uncomp(struct aec_stream *strm)
static int m_encode_se(struct aec_stream *strm) static int m_encode_se(struct aec_stream *strm)
{ {
size_t i;
uint32_t d;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
emit(state, 1, state->id_len + 1);