summaryrefslogtreecommitdiffstats
path: root/Utilities/cmliblzma/liblzma/common
diff options
context:
space:
mode:
authorDaniel Pfeifer <daniel@pfeifer-mail.de>2014-07-13 20:21:58 (GMT)
committerBrad King <brad.king@kitware.com>2014-07-29 12:44:36 (GMT)
commit7a92eddbcb2b2e6419062538e346908f0e502586 (patch)
treeb1985ad4a8904211f12cb07742a9d776fa28152f /Utilities/cmliblzma/liblzma/common
parentb2a07ca49c66665f5b51b592f44ecc4f66c7556b (diff)
downloadCMake-7a92eddbcb2b2e6419062538e346908f0e502586.zip
CMake-7a92eddbcb2b2e6419062538e346908f0e502586.tar.gz
CMake-7a92eddbcb2b2e6419062538e346908f0e502586.tar.bz2
liblzma: Port from C99 to C89/90
Remove use of designated initializers and declarations of variables after statements. Leave "//" comments as-is for now.
Diffstat (limited to 'Utilities/cmliblzma/liblzma/common')
-rw-r--r--Utilities/cmliblzma/liblzma/common/alone_decoder.c18
-rw-r--r--Utilities/cmliblzma/liblzma/common/alone_encoder.c22
-rw-r--r--Utilities/cmliblzma/liblzma/common/auto_decoder.c2
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c8
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c40
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_decoder.c2
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_encoder.c2
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_header_decoder.c21
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_header_encoder.c19
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_util.c11
-rw-r--r--Utilities/cmliblzma/liblzma/common/common.c12
-rw-r--r--Utilities/cmliblzma/liblzma/common/common.h64
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c12
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c11
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_common.c125
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_decoder.c80
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_encoder.c133
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_flags_decoder.c6
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c3
-rw-r--r--Utilities/cmliblzma/liblzma/common/index.c102
-rw-r--r--Utilities/cmliblzma/liblzma/common/index_decoder.c16
-rw-r--r--Utilities/cmliblzma/liblzma/common/index_encoder.c11
-rw-r--r--Utilities/cmliblzma/liblzma/common/index_hash.c10
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c6
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c22
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_decoder.c28
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_encoder.c35
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c8
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c8
-rw-r--r--Utilities/cmliblzma/liblzma/common/vli_size.c3
30 files changed, 490 insertions, 350 deletions
diff --git a/Utilities/cmliblzma/liblzma/common/alone_decoder.c b/Utilities/cmliblzma/liblzma/common/alone_decoder.c
index c25112e..a20cf49 100644
--- a/Utilities/cmliblzma/liblzma/common/alone_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/alone_decoder.c
@@ -126,19 +126,17 @@ alone_decode(lzma_coder *coder,
// Fall through
case SEQ_CODER_INIT: {
- if (coder->memusage > coder->memlimit)
- return LZMA_MEMLIMIT_ERROR;
+ lzma_ret ret;
lzma_filter_info filters[2] = {
- {
- .init = &lzma_lzma_decoder_init,
- .options = &coder->options,
- }, {
- .init = NULL,
- }
+ { 0, &lzma_lzma_decoder_init, &coder->options },
+ { 0, NULL, NULL }
};
- const lzma_ret ret = lzma_next_filter_init(&coder->next,
+ if (coder->memusage > coder->memlimit)
+ return LZMA_MEMLIMIT_ERROR;
+
+ ret = lzma_next_filter_init(&coder->next,
allocator, filters);
if (ret != LZMA_OK)
return ret;
@@ -229,7 +227,7 @@ lzma_alone_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern LZMA_API(lzma_ret)
lzma_alone_decoder(lzma_stream *strm, uint64_t memlimit)
{
- lzma_next_strm_init(lzma_alone_decoder_init, strm, memlimit, false);
+ lzma_next_strm_init2(lzma_alone_decoder_init, strm, memlimit, false);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/alone_encoder.c b/Utilities/cmliblzma/liblzma/common/alone_encoder.c
index eb1697e..62df126 100644
--- a/Utilities/cmliblzma/liblzma/common/alone_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/alone_encoder.c
@@ -78,6 +78,14 @@ static lzma_ret
alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
const lzma_options_lzma *options)
{
+ uint32_t d;
+
+ // Initialize the LZMA encoder.
+ const lzma_filter_info filters[2] = {
+ { 0, &lzma_lzma_encoder_init, (void *)(options) },
+ { 0, NULL, NULL }
+ };
+
lzma_next_coder_init(&alone_encoder_init, next, allocator);
if (next->coder == NULL) {
@@ -107,7 +115,7 @@ alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
// one is the next unless it is UINT32_MAX. While the header would
// allow any 32-bit integer, we do this to keep the decoder of liblzma
// accepting the resulting files.
- uint32_t d = options->dict_size - 1;
+ d = options->dict_size - 1;
d |= d >> 2;
d |= d >> 3;
d |= d >> 4;
@@ -121,16 +129,6 @@ alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
// - Uncompressed size (always unknown and using EOPM)
memset(next->coder->header + 1 + 4, 0xFF, 8);
- // Initialize the LZMA encoder.
- const lzma_filter_info filters[2] = {
- {
- .init = &lzma_lzma_encoder_init,
- .options = (void *)(options),
- }, {
- .init = NULL,
- }
- };
-
return lzma_next_filter_init(&next->coder->next, allocator, filters);
}
@@ -148,7 +146,7 @@ lzma_alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern LZMA_API(lzma_ret)
lzma_alone_encoder(lzma_stream *strm, const lzma_options_lzma *options)
{
- lzma_next_strm_init(alone_encoder_init, strm, options);
+ lzma_next_strm_init1(alone_encoder_init, strm, options);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/auto_decoder.c b/Utilities/cmliblzma/liblzma/common/auto_decoder.c
index 35c895f..6f3c862 100644
--- a/Utilities/cmliblzma/liblzma/common/auto_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/auto_decoder.c
@@ -177,7 +177,7 @@ auto_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern LZMA_API(lzma_ret)
lzma_auto_decoder(lzma_stream *strm, uint64_t memlimit, uint32_t flags)
{
- lzma_next_strm_init(auto_decoder_init, strm, memlimit, flags);
+ lzma_next_strm_init2(auto_decoder_init, strm, memlimit, flags);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c b/Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c
index ff27a11..b4bd388 100644
--- a/Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c
@@ -18,6 +18,9 @@ lzma_block_buffer_decode(lzma_block *block, lzma_allocator *allocator,
const uint8_t *in, size_t *in_pos, size_t in_size,
uint8_t *out, size_t *out_pos, size_t out_size)
{
+ lzma_next_coder block_decoder;
+ lzma_ret ret;
+
if (in_pos == NULL || (in == NULL && *in_pos != in_size)
|| *in_pos > in_size || out_pos == NULL
|| (out == NULL && *out_pos != out_size)
@@ -25,9 +28,8 @@ lzma_block_buffer_decode(lzma_block *block, lzma_allocator *allocator,
return LZMA_PROG_ERROR;
// Initialize the Block decoder.
- lzma_next_coder block_decoder = LZMA_NEXT_CODER_INIT;
- lzma_ret ret = lzma_block_decoder_init(
- &block_decoder, allocator, block);
+ block_decoder = LZMA_NEXT_CODER_INIT;
+ ret = lzma_block_decoder_init(&block_decoder, allocator, block);
if (ret == LZMA_OK) {
// Save the positions so that we can restore them in case
diff --git a/Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c b/Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c
index 519c6a6..136f7f5 100644
--- a/Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c
@@ -31,6 +31,8 @@
static lzma_vli
lzma2_bound(lzma_vli uncompressed_size)
{
+ lzma_vli overhead;
+
// Prevent integer overflow in overhead calculation.
if (uncompressed_size > COMPRESSED_SIZE_MAX)
return 0;
@@ -39,7 +41,7 @@ lzma2_bound(lzma_vli uncompressed_size)
// uncompressed_size up to the next multiple of LZMA2_CHUNK_MAX,
// multiply by the size of per-chunk header, and add one byte for
// the end marker.
- const lzma_vli overhead = ((uncompressed_size + LZMA2_CHUNK_MAX - 1)
+ overhead = ((uncompressed_size + LZMA2_CHUNK_MAX - 1)
/ LZMA2_CHUNK_MAX)
* LZMA2_HEADER_UNCOMPRESSED + 1;
@@ -82,15 +84,17 @@ static lzma_ret
block_encode_uncompressed(lzma_block *block, const uint8_t *in, size_t in_size,
uint8_t *out, size_t *out_pos, size_t out_size)
{
+ size_t in_pos = 0;
+ uint8_t control = 0x01; // Dictionary reset
+ lzma_filter *filters_orig;
+
// TODO: Figure out if the last filter is LZMA2 or Subblock and use
// that filter to encode the uncompressed chunks.
// Use LZMA2 uncompressed chunks. We wouldn't need a dictionary at
// all, but LZMA2 always requires a dictionary, so use the minimum
// value to minimize memory usage of the decoder.
- lzma_options_lzma lzma2 = {
- .dict_size = LZMA_DICT_SIZE_MIN,
- };
+ lzma_options_lzma lzma2 = { LZMA_DICT_SIZE_MIN };
lzma_filter filters[2];
filters[0].id = LZMA_FILTER_LZMA2;
@@ -99,7 +103,7 @@ block_encode_uncompressed(lzma_block *block, const uint8_t *in, size_t in_size,
// Set the above filter options to *block temporarily so that we can
// encode the Block Header.
- lzma_filter *filters_orig = block->filters;
+ filters_orig = block->filters;
block->filters = filters;
if (lzma_block_header_size(block) != LZMA_OK) {
@@ -128,18 +132,17 @@ block_encode_uncompressed(lzma_block *block, const uint8_t *in, size_t in_size,
*out_pos += block->header_size;
// Encode the data using LZMA2 uncompressed chunks.
- size_t in_pos = 0;
- uint8_t control = 0x01; // Dictionary reset
while (in_pos < in_size) {
+ size_t copy_size;
+
// Control byte: Indicate uncompressed chunk, of which
// the first resets the dictionary.
out[(*out_pos)++] = control;
control = 0x02; // No dictionary reset
// Size of the uncompressed chunk
- const size_t copy_size
- = my_min(in_size - in_pos, LZMA2_CHUNK_MAX);
+ copy_size = my_min(in_size - in_pos, LZMA2_CHUNK_MAX);
out[(*out_pos)++] = (copy_size - 1) >> 8;
out[(*out_pos)++] = (copy_size - 1) & 0xFF;
@@ -164,6 +167,10 @@ block_encode_normal(lzma_block *block, lzma_allocator *allocator,
const uint8_t *in, size_t in_size,
uint8_t *out, size_t *out_pos, size_t out_size)
{
+ size_t out_start;
+ lzma_next_coder raw_encoder = LZMA_NEXT_CODER_INIT;
+ lzma_ret ret;
+
// Find out the size of the Block Header.
block->compressed_size = lzma2_bound(in_size);
if (block->compressed_size == 0)
@@ -176,7 +183,7 @@ block_encode_normal(lzma_block *block, lzma_allocator *allocator,
if (out_size - *out_pos <= block->header_size)
return LZMA_BUF_ERROR;
- const size_t out_start = *out_pos;
+ out_start = *out_pos;
*out_pos += block->header_size;
// Limit out_size so that we stop encoding if the output would grow
@@ -186,8 +193,7 @@ block_encode_normal(lzma_block *block, lzma_allocator *allocator,
// TODO: In many common cases this could be optimized to use
// significantly less memory.
- lzma_next_coder raw_encoder = LZMA_NEXT_CODER_INIT;
- lzma_ret ret = lzma_raw_encoder_init(
+ ret = lzma_raw_encoder_init(
&raw_encoder, allocator, block->filters);
if (ret == LZMA_OK) {
@@ -226,6 +232,10 @@ lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
const uint8_t *in, size_t in_size,
uint8_t *out, size_t *out_pos, size_t out_size)
{
+ size_t check_size;
+ lzma_ret ret;
+ size_t i;
+
// Validate the arguments.
if (block == NULL || (in == NULL && in_size != 0) || out == NULL
|| out_pos == NULL || *out_pos > out_size)
@@ -249,7 +259,7 @@ lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
out_size -= (out_size - *out_pos) & 3;
// Get the size of the Check field.
- const size_t check_size = lzma_check_size(block->check);
+ check_size = lzma_check_size(block->check);
assert(check_size != UINT32_MAX);
// Reserve space for the Check field.
@@ -259,7 +269,7 @@ lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
out_size -= check_size;
// Do the actual compression.
- const lzma_ret ret = block_encode_normal(block, allocator,
+ ret = block_encode_normal(block, allocator,
in, in_size, out, out_pos, out_size);
if (ret != LZMA_OK) {
// If the error was something else than output buffer
@@ -281,7 +291,7 @@ lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
// Block Padding. No buffer overflow here, because we already adjusted
// out_size so that (out_size - out_start) is a multiple of four.
// Thus, if the buffer is full, the loop body can never run.
- for (size_t i = (size_t)(block->compressed_size); i & 3; ++i) {
+ for (i = (size_t)(block->compressed_size); i & 3; ++i) {
assert(*out_pos < out_size);
out[(*out_pos)++] = 0x00;
}
diff --git a/Utilities/cmliblzma/liblzma/common/block_decoder.c b/Utilities/cmliblzma/liblzma/common/block_decoder.c
index a3ce6f4..3de3851 100644
--- a/Utilities/cmliblzma/liblzma/common/block_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/block_decoder.c
@@ -233,7 +233,7 @@ lzma_block_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern LZMA_API(lzma_ret)
lzma_block_decoder(lzma_stream *strm, lzma_block *block)
{
- lzma_next_strm_init(lzma_block_decoder_init, strm, block);
+ lzma_next_strm_init1(lzma_block_decoder_init, strm, block);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/block_encoder.c b/Utilities/cmliblzma/liblzma/common/block_encoder.c
index 1eeb502..63e2687 100644
--- a/Utilities/cmliblzma/liblzma/common/block_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/block_encoder.c
@@ -208,7 +208,7 @@ lzma_block_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern LZMA_API(lzma_ret)
lzma_block_encoder(lzma_stream *strm, lzma_block *block)
{
- lzma_next_strm_init(lzma_block_encoder_init, strm, block);
+ lzma_next_strm_init1(lzma_block_encoder_init, strm, block);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/block_header_decoder.c b/Utilities/cmliblzma/liblzma/common/block_header_decoder.c
index 2c9573e..f6e470e 100644
--- a/Utilities/cmliblzma/liblzma/common/block_header_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/block_header_decoder.c
@@ -17,10 +17,12 @@
static void
free_properties(lzma_block *block, lzma_allocator *allocator)
{
+ size_t i;
+
// Free allocated filter options. The last array member is not
// touched after the initialization in the beginning of
// lzma_block_header_decode(), so we don't need to touch that here.
- for (size_t i = 0; i < LZMA_FILTERS_MAX; ++i) {
+ for (i = 0; i < LZMA_FILTERS_MAX; ++i) {
lzma_free(block->filters[i].options, allocator);
block->filters[i].id = LZMA_VLI_UNKNOWN;
block->filters[i].options = NULL;
@@ -34,6 +36,13 @@ extern LZMA_API(lzma_ret)
lzma_block_header_decode(lzma_block *block,
lzma_allocator *allocator, const uint8_t *in)
{
+ const size_t filter_count = (in[1] & 3) + 1;
+ size_t in_size;
+ size_t i;
+
+ // Start after the Block Header Size and Block Flags fields.
+ size_t in_pos = 2;
+
// NOTE: We consider the header to be corrupt not only when the
// CRC32 doesn't match, but also when variable-length integers
// are invalid or over 63 bits, or if the header is too small
@@ -41,7 +50,7 @@ lzma_block_header_decode(lzma_block *block,
// Initialize the filter options array. This way the caller can
// safely free() the options even if an error occurs in this function.
- for (size_t i = 0; i <= LZMA_FILTERS_MAX; ++i) {
+ for (i = 0; i <= LZMA_FILTERS_MAX; ++i) {
block->filters[i].id = LZMA_VLI_UNKNOWN;
block->filters[i].options = NULL;
}
@@ -56,7 +65,7 @@ lzma_block_header_decode(lzma_block *block,
return LZMA_PROG_ERROR;
// Exclude the CRC32 field.
- const size_t in_size = block->header_size - 4;
+ in_size = block->header_size - 4;
// Verify CRC32
if (lzma_crc32(in, in_size, 0) != unaligned_read32le(in + in_size))
@@ -66,9 +75,6 @@ lzma_block_header_decode(lzma_block *block,
if (in[1] & 0x3C)
return LZMA_OPTIONS_ERROR;
- // Start after the Block Header Size and Block Flags fields.
- size_t in_pos = 2;
-
// Compressed Size
if (in[1] & 0x40) {
return_if_error(lzma_vli_decode(&block->compressed_size,
@@ -90,8 +96,7 @@ lzma_block_header_decode(lzma_block *block,
block->uncompressed_size = LZMA_VLI_UNKNOWN;
// Filter Flags
- const size_t filter_count = (in[1] & 3) + 1;
- for (size_t i = 0; i < filter_count; ++i) {
+ for (i = 0; i < filter_count; ++i) {
const lzma_ret ret = lzma_filter_flags_decode(
&block->filters[i], allocator,
in, &in_pos, in_size);
diff --git a/Utilities/cmliblzma/liblzma/common/block_header_encoder.c b/Utilities/cmliblzma/liblzma/common/block_header_encoder.c
index 707dd0c..650295c 100644
--- a/Utilities/cmliblzma/liblzma/common/block_header_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/block_header_encoder.c
@@ -17,12 +17,14 @@
extern LZMA_API(lzma_ret)
lzma_block_header_size(lzma_block *block)
{
- if (block->version != 0)
- return LZMA_OPTIONS_ERROR;
+ size_t i;
// Block Header Size + Block Flags + CRC32.
uint32_t size = 1 + 1 + 4;
+ if (block->version != 0)
+ return LZMA_OPTIONS_ERROR;
+
// Compressed Size
if (block->compressed_size != LZMA_VLI_UNKNOWN) {
const uint32_t add = lzma_vli_size(block->compressed_size);
@@ -45,12 +47,13 @@ lzma_block_header_size(lzma_block *block)
if (block->filters == NULL || block->filters[0].id == LZMA_VLI_UNKNOWN)
return LZMA_PROG_ERROR;
- for (size_t i = 0; block->filters[i].id != LZMA_VLI_UNKNOWN; ++i) {
+ for (i = 0; block->filters[i].id != LZMA_VLI_UNKNOWN; ++i) {
+ uint32_t add;
+
// Don't allow too many filters.
if (i == LZMA_FILTERS_MAX)
return LZMA_PROG_ERROR;
- uint32_t add;
return_if_error(lzma_filter_flags_size(&add,
block->filters + i));
@@ -73,20 +76,23 @@ lzma_block_header_size(lzma_block *block)
extern LZMA_API(lzma_ret)
lzma_block_header_encode(const lzma_block *block, uint8_t *out)
{
+ size_t out_size;
+ size_t out_pos = 2;
+ size_t filter_count = 0;
+
// Validate everything but filters.
if (lzma_block_unpadded_size(block) == 0
|| !lzma_vli_is_valid(block->uncompressed_size))
return LZMA_PROG_ERROR;
// Indicate the size of the buffer _excluding_ the CRC32 field.
- const size_t out_size = block->header_size - 4;
+ out_size = block->header_size - 4;
// Store the Block Header Size.
out[0] = out_size / 4;
// We write Block Flags in pieces.
out[1] = 0x00;
- size_t out_pos = 2;
// Compressed Size
if (block->compressed_size != LZMA_VLI_UNKNOWN) {
@@ -108,7 +114,6 @@ lzma_block_header_encode(const lzma_block *block, uint8_t *out)
if (block->filters == NULL || block->filters[0].id == LZMA_VLI_UNKNOWN)
return LZMA_PROG_ERROR;
- size_t filter_count = 0;
do {
// There can be a maximum of four filters.
if (filter_count == LZMA_FILTERS_MAX)
diff --git a/Utilities/cmliblzma/liblzma/common/block_util.c b/Utilities/cmliblzma/liblzma/common/block_util.c
index 62c9345..4cd34d1 100644
--- a/Utilities/cmliblzma/liblzma/common/block_util.c
+++ b/Utilities/cmliblzma/liblzma/common/block_util.c
@@ -17,11 +17,14 @@
extern LZMA_API(lzma_ret)
lzma_block_compressed_size(lzma_block *block, lzma_vli unpadded_size)
{
+ uint32_t container_size;
+ lzma_vli compressed_size;
+
// Validate everything but Uncompressed Size and filters.
if (lzma_block_unpadded_size(block) == 0)
return LZMA_PROG_ERROR;
- const uint32_t container_size = block->header_size
+ container_size = block->header_size
+ lzma_check_size(block->check);
// Validate that Compressed Size will be greater than zero.
@@ -31,7 +34,7 @@ lzma_block_compressed_size(lzma_block *block, lzma_vli unpadded_size)
// Calculate what Compressed Size is supposed to be.
// If Compressed Size was present in Block Header,
// compare that the new value matches it.
- const lzma_vli compressed_size = unpadded_size - container_size;
+ compressed_size = unpadded_size - container_size;
if (block->compressed_size != LZMA_VLI_UNKNOWN
&& block->compressed_size != compressed_size)
return LZMA_DATA_ERROR;
@@ -45,6 +48,8 @@ lzma_block_compressed_size(lzma_block *block, lzma_vli unpadded_size)
extern LZMA_API(lzma_vli)
lzma_block_unpadded_size(const lzma_block *block)
{
+ lzma_vli unpadded_size;
+
// Validate the values that we are interested in i.e. all but
// Uncompressed Size and the filters.
//
@@ -66,7 +71,7 @@ lzma_block_unpadded_size(const lzma_block *block)
return LZMA_VLI_UNKNOWN;
// Calculate Unpadded Size and validate it.
- const lzma_vli unpadded_size = block->compressed_size
+ unpadded_size = block->compressed_size
+ block->header_size
+ lzma_check_size(block->check);
diff --git a/Utilities/cmliblzma/liblzma/common/common.c b/Utilities/cmliblzma/liblzma/common/common.c
index b9e3860..d0105e1 100644
--- a/Utilities/cmliblzma/liblzma/common/common.c
+++ b/Utilities/cmliblzma/liblzma/common/common.c
@@ -38,12 +38,12 @@ lzma_version_string(void)
extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
lzma_alloc(size_t size, lzma_allocator *allocator)
{
+ void *ptr;
+
// Some malloc() variants return NULL if called with size == 0.
if (size == 0)
size = 1;
- void *ptr;
-
if (allocator != NULL && allocator->alloc != NULL)
ptr = allocator->alloc(allocator->opaque, 1, size);
else
@@ -173,6 +173,10 @@ lzma_strm_init(lzma_stream *strm)
extern LZMA_API(lzma_ret)
lzma_code(lzma_stream *strm, lzma_action action)
{
+ size_t in_pos = 0;
+ size_t out_pos = 0;
+ lzma_ret ret;
+
// Sanity checks
if ((strm->next_in == NULL && strm->avail_in != 0)
|| (strm->next_out == NULL && strm->avail_out != 0)
@@ -248,9 +252,7 @@ lzma_code(lzma_stream *strm, lzma_action action)
return LZMA_PROG_ERROR;
}
- size_t in_pos = 0;
- size_t out_pos = 0;
- lzma_ret ret = strm->internal->next.code(
+ ret = strm->internal->next.code(
strm->internal->next.coder, strm->allocator,
strm->next_in, &in_pos, strm->avail_in,
strm->next_out, &out_pos, strm->avail_out, action);
diff --git a/Utilities/cmliblzma/liblzma/common/common.h b/Utilities/cmliblzma/liblzma/common/common.h
index 6d7412f..a1a1591 100644
--- a/Utilities/cmliblzma/liblzma/common/common.h
+++ b/Utilities/cmliblzma/liblzma/common/common.h
@@ -155,18 +155,18 @@ struct lzma_next_coder_s {
};
-/// Macro to initialize lzma_next_coder structure
-#define LZMA_NEXT_CODER_INIT \
- (lzma_next_coder){ \
- .coder = NULL, \
- .init = (uintptr_t)(NULL), \
- .id = LZMA_VLI_UNKNOWN, \
- .code = NULL, \
- .end = NULL, \
- .get_check = NULL, \
- .memconfig = NULL, \
- .update = NULL, \
- }
+/// Constant to initialize lzma_next_coder structure
+static const lzma_next_coder LZMA_NEXT_CODER_INIT =
+ {
+ NULL,
+ LZMA_VLI_UNKNOWN,
+ (uintptr_t)(NULL),
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ };
/// Internal data for lzma_strm_init, lzma_code, and lzma_end. A pointer to
@@ -211,7 +211,7 @@ extern void lzma_free(void *ptr, lzma_allocator *allocator);
/// Allocates strm->internal if it is NULL, and initializes *strm and
-/// strm->internal. This function is only called via lzma_next_strm_init macro.
+/// strm->internal. This function is only called via lzma_next_strm_init2 macro.
extern lzma_ret lzma_strm_init(lzma_stream *strm);
/// Initializes the next filter in the chain, if any. This takes care of
@@ -269,15 +269,37 @@ do { \
/// (The function being called will use lzma_next_coder_init()). If
/// initialization fails, memory that wasn't freed by func() is freed
/// along strm->internal.
-#define lzma_next_strm_init(func, strm, ...) \
+#define lzma_next_strm_init1(func, strm, arg1) \
do { \
- return_if_error(lzma_strm_init(strm)); \
- const lzma_ret ret_ = func(&(strm)->internal->next, \
- (strm)->allocator, __VA_ARGS__); \
- if (ret_ != LZMA_OK) { \
- lzma_end(strm); \
- return ret_; \
- } \
+ lzma_ret ret_; \
+ return_if_error(lzma_strm_init(strm)); \
+ ret_ = func(&(strm)->internal->next, (strm)->allocator, arg1); \
+ if (ret_ != LZMA_OK) { \
+ lzma_end(strm); \
+ return ret_; \
+ } \
+} while (0)
+
+#define lzma_next_strm_init2(func, strm, arg1, arg2) \
+do { \
+ lzma_ret ret_; \
+ return_if_error(lzma_strm_init(strm)); \
+ ret_ = func(&(strm)->internal->next, (strm)->allocator, arg1, arg2); \
+ if (ret_ != LZMA_OK) { \
+ lzma_end(strm); \
+ return ret_; \
+ } \
+} while (0)
+
+#define lzma_next_strm_init3(func, strm, arg1, arg2, arg3) \
+do { \
+ lzma_ret ret_; \
+ return_if_error(lzma_strm_init(strm)); \
+ ret_ = func(&(strm)->internal->next, (strm)->allocator, arg1, arg2, arg3); \
+ if (ret_ != LZMA_OK) { \
+ lzma_end(strm); \
+ return ret_; \
+ } \
} while (0)
#endif
diff --git a/Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c b/Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c
index 2d35ef8..65665c1 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c
@@ -18,22 +18,26 @@ lzma_raw_buffer_decode(const lzma_filter *filters, lzma_allocator *allocator,
const uint8_t *in, size_t *in_pos, size_t in_size,
uint8_t *out, size_t *out_pos, size_t out_size)
{
+ lzma_next_coder next = LZMA_NEXT_CODER_INIT;
+ size_t in_start;
+ size_t out_start;
+ lzma_ret ret;
+
// Validate what isn't validated later in filter_common.c.
if (in == NULL || in_pos == NULL || *in_pos > in_size || out == NULL
|| out_pos == NULL || *out_pos > out_size)
return LZMA_PROG_ERROR;
// Initialize the decoer.
- lzma_next_coder next = LZMA_NEXT_CODER_INIT;
return_if_error(lzma_raw_decoder_init(&next, allocator, filters));
// Store the positions so that we can restore them if something
// goes wrong.
- const size_t in_start = *in_pos;
- const size_t out_start = *out_pos;
+ in_start = *in_pos;
+ out_start = *out_pos;
// Do the actual decoding and free decoder's memory.
- lzma_ret ret = next.code(next.coder, allocator, in, in_pos, in_size,
+ ret = next.code(next.coder, allocator, in, in_pos, in_size,
out, out_pos, out_size, LZMA_FINISH);
if (ret == LZMA_STREAM_END) {
diff --git a/Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c b/Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c
index 646e1b3..b23329f 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c
@@ -18,22 +18,25 @@ lzma_raw_buffer_encode(const lzma_filter *filters, lzma_allocator *allocator,
const uint8_t *in, size_t in_size, uint8_t *out,
size_t *out_pos, size_t out_size)
{
+ lzma_next_coder next = LZMA_NEXT_CODER_INIT;
+ size_t out_start;
+ size_t in_pos = 0;
+ lzma_ret ret;
+
// Validate what isn't validated later in filter_common.c.
if ((in == NULL && in_size != 0) || out == NULL
|| out_pos == NULL || *out_pos > out_size)
return LZMA_PROG_ERROR;
// Initialize the encoder
- lzma_next_coder next = LZMA_NEXT_CODER_INIT;
return_if_error(lzma_raw_encoder_init(&next, allocator, filters));
// Store the output position so that we can restore it if
// something goes wrong.
- const size_t out_start = *out_pos;
+ out_start = *out_pos;
// Do the actual encoding and free coder's memory.
- size_t in_pos = 0;
- lzma_ret ret = next.code(next.coder, allocator, in, &in_pos, in_size,
+ ret = next.code(next.coder, allocator, in, &in_pos, in_size,
out, out_pos, out_size, LZMA_FINISH);
lzma_next_end(&next, allocator);
diff --git a/Utilities/cmliblzma/liblzma/common/filter_common.c b/Utilities/cmliblzma/liblzma/common/filter_common.c
index 7c95b05..d2b9e08 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_common.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_common.c
@@ -36,87 +36,87 @@ static const struct {
} features[] = {
#if defined (HAVE_ENCODER_LZMA1) || defined(HAVE_DECODER_LZMA1)
{
- .id = LZMA_FILTER_LZMA1,
- .options_size = sizeof(lzma_options_lzma),
- .non_last_ok = false,
- .last_ok = true,
- .changes_size = true,
+ LZMA_FILTER_LZMA1,
+ sizeof(lzma_options_lzma),
+ false,
+ true,
+ true,
},
#endif
#if defined(HAVE_ENCODER_LZMA2) || defined(HAVE_DECODER_LZMA2)
{
- .id = LZMA_FILTER_LZMA2,
- .options_size = sizeof(lzma_options_lzma),
- .non_last_ok = false,
- .last_ok = true,
- .changes_size = true,
+ LZMA_FILTER_LZMA2,
+ sizeof(lzma_options_lzma),
+ false,
+ true,
+ true,
},
#endif
#if defined(HAVE_ENCODER_X86) || defined(HAVE_DECODER_X86)
{
- .id = LZMA_FILTER_X86,
- .options_size = sizeof(lzma_options_bcj),
- .non_last_ok = true,
- .last_ok = false,
- .changes_size = false,
+ LZMA_FILTER_X86,
+ sizeof(lzma_options_bcj),
+ true,
+ false,
+ false,
},
#endif
#if defined(HAVE_ENCODER_POWERPC) || defined(HAVE_DECODER_POWERPC)
{
- .id = LZMA_FILTER_POWERPC,
- .options_size = sizeof(lzma_options_bcj),
- .non_last_ok = true,
- .last_ok = false,
- .changes_size = false,
+ LZMA_FILTER_POWERPC,
+ sizeof(lzma_options_bcj),
+ true,
+ false,
+ false,
},
#endif
#if defined(HAVE_ENCODER_IA64) || defined(HAVE_DECODER_IA64)
{
- .id = LZMA_FILTER_IA64,
- .options_size = sizeof(lzma_options_bcj),
- .non_last_ok = true,
- .last_ok = false,
- .changes_size = false,
+ LZMA_FILTER_IA64,
+ sizeof(lzma_options_bcj),
+ true,
+ false,
+ false,
},
#endif
#if defined(HAVE_ENCODER_ARM) || defined(HAVE_DECODER_ARM)
{
- .id = LZMA_FILTER_ARM,
- .options_size = sizeof(lzma_options_bcj),
- .non_last_ok = true,
- .last_ok = false,
- .changes_size = false,
+ LZMA_FILTER_ARM,
+ sizeof(lzma_options_bcj),
+ true,
+ false,
+ false,
},
#endif
#if defined(HAVE_ENCODER_ARMTHUMB) || defined(HAVE_DECODER_ARMTHUMB)
{
- .id = LZMA_FILTER_ARMTHUMB,
- .options_size = sizeof(lzma_options_bcj),
- .non_last_ok = true,
- .last_ok = false,
- .changes_size = false,
+ LZMA_FILTER_ARMTHUMB,
+ sizeof(lzma_options_bcj),
+ true,
+ false,
+ false,
},
#endif
#if defined(HAVE_ENCODER_SPARC) || defined(HAVE_DECODER_SPARC)
{
- .id = LZMA_FILTER_SPARC,
- .options_size = sizeof(lzma_options_bcj),
- .non_last_ok = true,
- .last_ok = false,
- .changes_size = false,
+ LZMA_FILTER_SPARC,
+ sizeof(lzma_options_bcj),
+ true,
+ false,
+ false,
},
#endif
#if defined(HAVE_ENCODER_DELTA) || defined(HAVE_DECODER_DELTA)
{
- .id = LZMA_FILTER_DELTA,
- .options_size = sizeof(lzma_options_delta),
- .non_last_ok = true,
- .last_ok = false,
- .changes_size = false,
+ LZMA_FILTER_DELTA,
+ sizeof(lzma_options_delta),
+ true,
+ false,
+ false,
},
#endif
{
- .id = LZMA_VLI_UNKNOWN
+ LZMA_VLI_UNKNOWN
}
};
@@ -125,11 +125,12 @@ extern LZMA_API(lzma_ret)
lzma_filters_copy(const lzma_filter *src, lzma_filter *dest,
lzma_allocator *allocator)
{
+ size_t i;
+ lzma_ret ret;
+
if (src == NULL || dest == NULL)
return LZMA_PROG_ERROR;
- lzma_ret ret;
- size_t i;
for (i = 0; src[i].id != LZMA_VLI_UNKNOWN; ++i) {
// There must be a maximum of four filters plus
// the array terminator.
@@ -193,10 +194,6 @@ error:
static lzma_ret
validate_chain(const lzma_filter *filters, size_t *count)
{
- // There must be at least one filter.
- if (filters == NULL || filters[0].id == LZMA_VLI_UNKNOWN)
- return LZMA_PROG_ERROR;
-
// Number of non-last filters that may change the size of the data
// significantly (that is, more than 1-2 % or so).
size_t changes_size_count = 0;
@@ -210,6 +207,11 @@ validate_chain(const lzma_filter *filters, size_t *count)
bool last_ok = false;
size_t i = 0;
+
+ // There must be at least one filter.
+ if (filters == NULL || filters[0].id == LZMA_VLI_UNKNOWN)
+ return LZMA_PROG_ERROR;
+
do {
size_t j;
for (j = 0; filters[i].id != features[j].id; ++j)
@@ -243,14 +245,17 @@ lzma_raw_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
const lzma_filter *options,
lzma_filter_find coder_find, bool is_encoder)
{
- // Do some basic validation and get the number of filters.
+ lzma_filter_info filters[LZMA_FILTERS_MAX + 1];
size_t count;
+ size_t i;
+ lzma_ret ret;
+
+ // Do some basic validation and get the number of filters.
return_if_error(validate_chain(options, &count));
// Set the filter functions and copy the options pointer.
- lzma_filter_info filters[LZMA_FILTERS_MAX + 1];
if (is_encoder) {
- for (size_t i = 0; i < count; ++i) {
+ for (i = 0; i < count; ++i) {
// The order of the filters is reversed in the
// encoder. It allows more efficient handling
// of the uncompressed data.
@@ -266,7 +271,7 @@ lzma_raw_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
filters[j].options = options[i].options;
}
} else {
- for (size_t i = 0; i < count; ++i) {
+ for (i = 0; i < count; ++i) {
const lzma_filter_coder *const fc
= coder_find(options[i].id);
if (fc == NULL || fc->init == NULL)
@@ -283,7 +288,7 @@ lzma_raw_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
filters[count].init = NULL;
// Initialize the filters.
- const lzma_ret ret = lzma_next_filter_init(next, allocator, filters);
+ ret = lzma_next_filter_init(next, allocator, filters);
if (ret != LZMA_OK)
lzma_next_end(next, allocator);
@@ -295,6 +300,9 @@ extern uint64_t
lzma_raw_coder_memusage(lzma_filter_find coder_find,
const lzma_filter *filters)
{
+ uint64_t total = 0;
+ size_t i = 0;
+
// The chain has to have at least one filter.
{
size_t tmp;
@@ -302,9 +310,6 @@ lzma_raw_coder_memusage(lzma_filter_find coder_find,
return UINT64_MAX;
}
- uint64_t total = 0;
- size_t i = 0;
-
do {
const lzma_filter_coder *const fc
= coder_find(filters[i].id);
diff --git a/Utilities/cmliblzma/liblzma/common/filter_decoder.c b/Utilities/cmliblzma/liblzma/common/filter_decoder.c
index 1ebbe2a..cce2b30 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_decoder.c
@@ -44,74 +44,74 @@ typedef struct {
static const lzma_filter_decoder decoders[] = {
#ifdef HAVE_DECODER_LZMA1
{
- .id = LZMA_FILTER_LZMA1,
- .init = &lzma_lzma_decoder_init,
- .memusage = &lzma_lzma_decoder_memusage,
- .props_decode = &lzma_lzma_props_decode,
+ LZMA_FILTER_LZMA1,
+ &lzma_lzma_decoder_init,
+ &lzma_lzma_decoder_memusage,
+ &lzma_lzma_props_decode,
},
#endif
#ifdef HAVE_DECODER_LZMA2
{
- .id = LZMA_FILTER_LZMA2,
- .init = &lzma_lzma2_decoder_init,
- .memusage = &lzma_lzma2_decoder_memusage,
- .props_decode = &lzma_lzma2_props_decode,
+ LZMA_FILTER_LZMA2,
+ &lzma_lzma2_decoder_init,
+ &lzma_lzma2_decoder_memusage,
+ &lzma_lzma2_props_decode,
},
#endif
#ifdef HAVE_DECODER_X86
{
- .id = LZMA_FILTER_X86,
- .init = &lzma_simple_x86_decoder_init,
- .memusage = NULL,
- .props_decode = &lzma_simple_props_decode,
+ LZMA_FILTER_X86,
+ &lzma_simple_x86_decoder_init,
+ NULL,
+ &lzma_simple_props_decode,
},
#endif
#ifdef HAVE_DECODER_POWERPC
{
- .id = LZMA_FILTER_POWERPC,
- .init = &lzma_simple_powerpc_decoder_init,
- .memusage = NULL,
- .props_decode = &lzma_simple_props_decode,
+ LZMA_FILTER_POWERPC,
+ &lzma_simple_powerpc_decoder_init,
+ NULL,
+ &lzma_simple_props_decode,
},
#endif
#ifdef HAVE_DECODER_IA64
{
- .id = LZMA_FILTER_IA64,
- .init = &lzma_simple_ia64_decoder_init,
- .memusage = NULL,
- .props_decode = &lzma_simple_props_decode,
+ LZMA_FILTER_IA64,
+ &lzma_simple_ia64_decoder_init,
+ NULL,
+ &lzma_simple_props_decode,
},
#endif
#ifdef HAVE_DECODER_ARM
{
- .id = LZMA_FILTER_ARM,
- .init = &lzma_simple_arm_decoder_init,
- .memusage = NULL,
- .props_decode = &lzma_simple_props_decode,
+ LZMA_FILTER_ARM,
+ &lzma_simple_arm_decoder_init,
+ NULL,
+ &lzma_simple_props_decode,
},
#endif
#ifdef HAVE_DECODER_ARMTHUMB
{
- .id = LZMA_FILTER_ARMTHUMB,
- .init = &lzma_simple_armthumb_decoder_init,
- .memusage = NULL,
- .props_decode = &lzma_simple_props_decode,
+ LZMA_FILTER_ARMTHUMB,
+ &lzma_simple_armthumb_decoder_init,
+ NULL,
+ &lzma_simple_props_decode,
},
#endif
#ifdef HAVE_DECODER_SPARC
{
- .id = LZMA_FILTER_SPARC,
- .init = &lzma_simple_sparc_decoder_init,
- .memusage = NULL,
- .props_decode = &lzma_simple_props_decode,
+ LZMA_FILTER_SPARC,
+ &lzma_simple_sparc_decoder_init,
+ NULL,
+ &lzma_simple_props_decode,
},
#endif
#ifdef HAVE_DECODER_DELTA
{
- .id = LZMA_FILTER_DELTA,
- .init = &lzma_delta_decoder_init,
- .memusage = &lzma_delta_coder_memusage,
- .props_decode = &lzma_delta_props_decode,
+ LZMA_FILTER_DELTA,
+ &lzma_delta_decoder_init,
+ &lzma_delta_coder_memusage,
+ &lzma_delta_props_decode,
},
#endif
};
@@ -120,7 +120,8 @@ static const lzma_filter_decoder decoders[] = {
static const lzma_filter_decoder *
decoder_find(lzma_vli id)
{
- for (size_t i = 0; i < ARRAY_SIZE(decoders); ++i)
+ size_t i;
+ for (i = 0; i < ARRAY_SIZE(decoders); ++i)
if (decoders[i].id == id)
return decoders + i;
@@ -147,7 +148,7 @@ lzma_raw_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern LZMA_API(lzma_ret)
lzma_raw_decoder(lzma_stream *strm, const lzma_filter *options)
{
- lzma_next_strm_init(lzma_raw_decoder_init, strm, options);
+ lzma_next_strm_init1(lzma_raw_decoder_init, strm, options);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
@@ -168,10 +169,11 @@ extern LZMA_API(lzma_ret)
lzma_properties_decode(lzma_filter *filter, lzma_allocator *allocator,
const uint8_t *props, size_t props_size)
{
+ const lzma_filter_decoder *const fd = decoder_find(filter->id);
+
// Make it always NULL so that the caller can always safely free() it.
filter->options = NULL;
- const lzma_filter_decoder *const fd = decoder_find(filter->id);
if (fd == NULL)
return LZMA_OPTIONS_ERROR;
diff --git a/Utilities/cmliblzma/liblzma/common/filter_encoder.c b/Utilities/cmliblzma/liblzma/common/filter_encoder.c
index 635d812..9fdb100 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_encoder.c
@@ -56,95 +56,101 @@ typedef struct {
static const lzma_filter_encoder encoders[] = {
#ifdef HAVE_ENCODER_LZMA1
{
- .id = LZMA_FILTER_LZMA1,
- .init = &lzma_lzma_encoder_init,
- .memusage = &lzma_lzma_encoder_memusage,
- .chunk_size = NULL, // FIXME
- .props_size_get = NULL,
- .props_size_fixed = 5,
- .props_encode = &lzma_lzma_props_encode,
+ LZMA_FILTER_LZMA1,
+ &lzma_lzma_encoder_init,
+ &lzma_lzma_encoder_memusage,
+ NULL, // FIXME
+ NULL,
+ 5,
+ &lzma_lzma_props_encode,
},
#endif
#ifdef HAVE_ENCODER_LZMA2
{
- .id = LZMA_FILTER_LZMA2,
- .init = &lzma_lzma2_encoder_init,
- .memusage = &lzma_lzma2_encoder_memusage,
- .chunk_size = NULL, // FIXME
- .props_size_get = NULL,
- .props_size_fixed = 1,
- .props_encode = &lzma_lzma2_props_encode,
+ LZMA_FILTER_LZMA2,
+ &lzma_lzma2_encoder_init,
+ &lzma_lzma2_encoder_memusage,
+ NULL, // FIXME
+ NULL,
+ 1,
+ &lzma_lzma2_props_encode,
},
#endif
#ifdef HAVE_ENCODER_X86
{
- .id = LZMA_FILTER_X86,
- .init = &lzma_simple_x86_encoder_init,
- .memusage = NULL,
- .chunk_size = NULL,
- .props_size_get = &lzma_simple_props_size,
- .props_encode = &lzma_simple_props_encode,
+ LZMA_FILTER_X86,
+ &lzma_simple_x86_encoder_init,
+ NULL,
+ NULL,
+ &lzma_simple_props_size,
+ 0,
+ &lzma_simple_props_encode,
},
#endif
#ifdef HAVE_ENCODER_POWERPC
{
- .id = LZMA_FILTER_POWERPC,
- .init = &lzma_simple_powerpc_encoder_init,
- .memusage = NULL,
- .chunk_size = NULL,
- .props_size_get = &lzma_simple_props_size,
- .props_encode = &lzma_simple_props_encode,
+ LZMA_FILTER_POWERPC,
+ &lzma_simple_powerpc_encoder_init,
+ NULL,
+ NULL,
+ &lzma_simple_props_size,
+ 0,
+ &lzma_simple_props_encode,
},
#endif
#ifdef HAVE_ENCODER_IA64
{
- .id = LZMA_FILTER_IA64,
- .init = &lzma_simple_ia64_encoder_init,
- .memusage = NULL,
- .chunk_size = NULL,
- .props_size_get = &lzma_simple_props_size,
- .props_encode = &lzma_simple_props_encode,
+ LZMA_FILTER_IA64,
+ &lzma_simple_ia64_encoder_init,
+ NULL,
+ NULL,
+ &lzma_simple_props_size,
+ 0,
+ &lzma_simple_props_encode,
},
#endif
#ifdef HAVE_ENCODER_ARM
{
- .id = LZMA_FILTER_ARM,
- .init = &lzma_simple_arm_encoder_init,
- .memusage = NULL,
- .chunk_size = NULL,
- .props_size_get = &lzma_simple_props_size,
- .props_encode = &lzma_simple_props_encode,
+ LZMA_FILTER_ARM,
+ &lzma_simple_arm_encoder_init,
+ NULL,
+ NULL,
+ &lzma_simple_props_size,
+ 0,
+ &lzma_simple_props_encode,
},
#endif
#ifdef HAVE_ENCODER_ARMTHUMB
{
- .id = LZMA_FILTER_ARMTHUMB,
- .init = &lzma_simple_armthumb_encoder_init,
- .memusage = NULL,
- .chunk_size = NULL,
- .props_size_get = &lzma_simple_props_size,
- .props_encode = &lzma_simple_props_encode,
+ LZMA_FILTER_ARMTHUMB,
+ &lzma_simple_armthumb_encoder_init,
+ NULL,
+ NULL,
+ &lzma_simple_props_size,
+ 0,
+ &lzma_simple_props_encode,
},
#endif
#ifdef HAVE_ENCODER_SPARC
{
- .id = LZMA_FILTER_SPARC,
- .init = &lzma_simple_sparc_encoder_init,
- .memusage = NULL,
- .chunk_size = NULL,
- .props_size_get = &lzma_simple_props_size,
- .props_encode = &lzma_simple_props_encode,
+ LZMA_FILTER_SPARC,
+ &lzma_simple_sparc_encoder_init,
+ NULL,
+ NULL,
+ &lzma_simple_props_size,
+ 0,
+ &lzma_simple_props_encode,
},
#endif
#ifdef HAVE_ENCODER_DELTA
{
- .id = LZMA_FILTER_DELTA,
- .init = &lzma_delta_encoder_init,
- .memusage = &lzma_delta_coder_memusage,
- .chunk_size = NULL,
- .props_size_get = NULL,
- .props_size_fixed = 1,
- .props_encode = &lzma_delta_props_encode,
+ LZMA_FILTER_DELTA,
+ &lzma_delta_encoder_init,
+ &lzma_delta_coder_memusage,
+ NULL,
+ NULL,
+ 1,
+ &lzma_delta_props_encode,
},
#endif
};
@@ -153,7 +159,8 @@ static const lzma_filter_encoder encoders[] = {
static const lzma_filter_encoder *
encoder_find(lzma_vli id)
{
- for (size_t i = 0; i < ARRAY_SIZE(encoders); ++i)
+ size_t i;
+ for (i = 0; i < ARRAY_SIZE(encoders); ++i)
if (encoders[i].id == id)
return encoders + i;
@@ -171,6 +178,10 @@ lzma_filter_encoder_is_supported(lzma_vli id)
extern LZMA_API(lzma_ret)
lzma_filters_update(lzma_stream *strm, const lzma_filter *filters)
{
+ size_t i;
+ size_t count = 1;
+ lzma_filter reversed_filters[LZMA_FILTERS_MAX + 1];
+
if (strm->internal->next.update == NULL)
return LZMA_PROG_ERROR;
@@ -180,12 +191,10 @@ lzma_filters_update(lzma_stream *strm, const lzma_filter *filters)
// The actual filter chain in the encoder is reversed. Some things
// still want the normal order chain, so we provide both.
- size_t count = 1;
while (filters[count].id != LZMA_VLI_UNKNOWN)
++count;
- lzma_filter reversed_filters[LZMA_FILTERS_MAX + 1];
- for (size_t i = 0; i < count; ++i)
+ for (i = 0; i < count; ++i)
reversed_filters[count - i - 1] = filters[i];
reversed_filters[count].id = LZMA_VLI_UNKNOWN;
@@ -207,7 +216,7 @@ lzma_raw_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern LZMA_API(lzma_ret)
lzma_raw_encoder(lzma_stream *strm, const lzma_filter *options)
{
- lzma_next_strm_init(lzma_raw_coder_init, strm, options,
+ lzma_next_strm_init3(lzma_raw_coder_init, strm, options,
(lzma_filter_find)(&encoder_find), true);
strm->internal->supported_actions[LZMA_RUN] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/filter_flags_decoder.c b/Utilities/cmliblzma/liblzma/common/filter_flags_decoder.c
index caae10c..aa2dbd5 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_flags_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_flags_decoder.c
@@ -18,6 +18,9 @@ lzma_filter_flags_decode(
lzma_filter *filter, lzma_allocator *allocator,
const uint8_t *in, size_t *in_pos, size_t in_size)
{
+ lzma_vli props_size;
+ lzma_ret ret;
+
// Set the pointer to NULL so the caller can always safely free it.
filter->options = NULL;
@@ -29,7 +32,6 @@ lzma_filter_flags_decode(
return LZMA_DATA_ERROR;
// Size of Properties
- lzma_vli props_size;
return_if_error(lzma_vli_decode(&props_size, NULL,
in, in_pos, in_size));
@@ -37,7 +39,7 @@ lzma_filter_flags_decode(
if (in_size - *in_pos < props_size)
return LZMA_DATA_ERROR;
- const lzma_ret ret = lzma_properties_decode(
+ ret = lzma_properties_decode(
filter, allocator, in + *in_pos, props_size);
*in_pos += props_size;
diff --git a/Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c b/Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c
index d110566..755c407 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c
@@ -31,6 +31,8 @@ extern LZMA_API(lzma_ret)
lzma_filter_flags_encode(const lzma_filter *filter,
uint8_t *out, size_t *out_pos, size_t out_size)
{
+ uint32_t props_size;
+
// Filter ID
if (filter->id >= LZMA_FILTER_RESERVED_START)
return LZMA_PROG_ERROR;
@@ -39,7 +41,6 @@ lzma_filter_flags_encode(const lzma_filter *filter,
out, out_pos, out_size));
// Size of Properties
- uint32_t props_size;
return_if_error(lzma_properties_size(&props_size, filter));
return_if_error(lzma_vli_encode(props_size, NULL,
out, out_pos, out_size));
diff --git a/Utilities/cmliblzma/liblzma/common/index.c b/Utilities/cmliblzma/liblzma/common/index.c
index 9af4bc1..f0f67ca 100644
--- a/Utilities/cmliblzma/liblzma/common/index.c
+++ b/Utilities/cmliblzma/liblzma/common/index.c
@@ -230,6 +230,7 @@ index_tree_end(index_tree *tree, lzma_allocator *allocator,
static void
index_tree_append(index_tree *tree, index_tree_node *node)
{
+ uint32_t up;
node->parent = tree->rightmost;
node->left = NULL;
node->right = NULL;
@@ -258,8 +259,10 @@ index_tree_append(index_tree *tree, index_tree_node *node)
// and thus know the state of the tree just by looking at the node
// count. From the node count we can calculate how many steps to go
// up in the tree to find the rotation root.
- uint32_t up = tree->count ^ (UINT32_C(1) << bsr32(tree->count));
+ up = tree->count ^ (UINT32_C(1) << bsr32(tree->count));
if (up != 0) {
+ index_tree_node *pivot;
+
// Locate the root node for the rotation.
up = ctz32(tree->count) + 2;
do {
@@ -267,7 +270,7 @@ index_tree_append(index_tree *tree, index_tree_node *node)
} while (--up > 0);
// Rotate left using node as the rotation root.
- index_tree_node *pivot = node->right;
+ pivot = node->right;
if (node->parent == NULL) {
tree->root = pivot;
@@ -397,11 +400,13 @@ index_init_plain(lzma_allocator *allocator)
extern LZMA_API(lzma_index *)
lzma_index_init(lzma_allocator *allocator)
{
+ index_stream *s;
+
lzma_index *i = index_init_plain(allocator);
if (i == NULL)
return NULL;
- index_stream *s = index_stream_init(0, 0, 1, 0, allocator);
+ s = index_stream_init(0, 0, 1, 0, allocator);
if (s == NULL) {
lzma_free(i, allocator);
return NULL;
@@ -600,6 +605,8 @@ lzma_index_padding_size(const lzma_index *i)
extern LZMA_API(lzma_ret)
lzma_index_stream_flags(lzma_index *i, const lzma_stream_flags *stream_flags)
{
+ index_stream *s;
+
if (i == NULL || stream_flags == NULL)
return LZMA_PROG_ERROR;
@@ -607,7 +614,7 @@ lzma_index_stream_flags(lzma_index *i, const lzma_stream_flags *stream_flags)
return_if_error(lzma_stream_flags_compare(
stream_flags, stream_flags));
- index_stream *s = (index_stream *)(i->streams.rightmost);
+ s = (index_stream *)(i->streams.rightmost);
s->stream_flags = *stream_flags;
return LZMA_OK;
@@ -617,14 +624,17 @@ lzma_index_stream_flags(lzma_index *i, const lzma_stream_flags *stream_flags)
extern LZMA_API(lzma_ret)
lzma_index_stream_padding(lzma_index *i, lzma_vli stream_padding)
{
+ index_stream *s;
+ lzma_vli old_stream_padding;
+
if (i == NULL || stream_padding > LZMA_VLI_MAX
|| (stream_padding & 3) != 0)
return LZMA_PROG_ERROR;
- index_stream *s = (index_stream *)(i->streams.rightmost);
+ s = (index_stream *)(i->streams.rightmost);
// Check that the new value won't make the file grow too big.
- const lzma_vli old_stream_padding = s->stream_padding;
+ old_stream_padding = s->stream_padding;
s->stream_padding = 0;
if (lzma_index_file_size(i) + stream_padding > LZMA_VLI_MAX) {
s->stream_padding = old_stream_padding;
@@ -640,20 +650,26 @@ extern LZMA_API(lzma_ret)
lzma_index_append(lzma_index *i, lzma_allocator *allocator,
lzma_vli unpadded_size, lzma_vli uncompressed_size)
{
+ index_stream *s;
+ index_group *g;
+ lzma_vli compressed_base;
+ lzma_vli uncompressed_base;
+ uint32_t index_list_size_add;
+
// Validate.
if (i == NULL || unpadded_size < UNPADDED_SIZE_MIN
|| unpadded_size > UNPADDED_SIZE_MAX
|| uncompressed_size > LZMA_VLI_MAX)
return LZMA_PROG_ERROR;
- index_stream *s = (index_stream *)(i->streams.rightmost);
- index_group *g = (index_group *)(s->groups.rightmost);
+ s = (index_stream *)(i->streams.rightmost);
+ g = (index_group *)(s->groups.rightmost);
- const lzma_vli compressed_base = g == NULL ? 0
+ compressed_base = g == NULL ? 0
: vli_ceil4(g->records[g->last].unpadded_sum);
- const lzma_vli uncompressed_base = g == NULL ? 0
+ uncompressed_base = g == NULL ? 0
: g->records[g->last].uncompressed_sum;
- const uint32_t index_list_size_add = lzma_vli_size(unpadded_size)
+ index_list_size_add = lzma_vli_size(unpadded_size)
+ lzma_vli_size(uncompressed_size);
// Check that the file size will stay within limits.
@@ -767,6 +783,7 @@ extern LZMA_API(lzma_ret)
lzma_index_cat(lzma_index *restrict dest, lzma_index *restrict src,
lzma_allocator *allocator)
{
+ index_cat_info info;
const lzma_vli dest_file_size = lzma_index_file_size(dest);
// Check that we don't exceed the file size limits.
@@ -796,10 +813,12 @@ lzma_index_cat(lzma_index *restrict dest, lzma_index *restrict src,
index_stream *s = (index_stream *)(dest->streams.rightmost);
index_group *g = (index_group *)(s->groups.rightmost);
if (g != NULL && g->last + 1 < g->allocated) {
+ index_group *newg;
+
assert(g->node.left == NULL);
assert(g->node.right == NULL);
- index_group *newg = lzma_alloc(sizeof(index_group)
+ newg = lzma_alloc(sizeof(index_group)
+ (g->last + 1)
* sizeof(index_record),
allocator);
@@ -834,13 +853,12 @@ lzma_index_cat(lzma_index *restrict dest, lzma_index *restrict src,
// Add all the Streams from src to dest. Update the base offsets
// of each Stream from src.
- const index_cat_info info = {
- .uncompressed_size = dest->uncompressed_size,
- .file_size = dest_file_size,
- .stream_number_add = dest->streams.count,
- .block_number_add = dest->record_count,
- .streams = &dest->streams,
- };
+ info.uncompressed_size = dest->uncompressed_size;
+ info.file_size = dest_file_size;
+ info.stream_number_add = dest->streams.count;
+ info.block_number_add = dest->record_count;
+ info.streams = &dest->streams;
+
index_cat_helper(&info, (index_stream *)(src->streams.root));
// Update info about all the combined Streams.
@@ -861,12 +879,17 @@ lzma_index_cat(lzma_index *restrict dest, lzma_index *restrict src,
static index_stream *
index_dup_stream(const index_stream *src, lzma_allocator *allocator)
{
+ index_stream *dest;
+ index_group *destg;
+ index_group *srcg;
+ size_t i = 0;
+
// Catch a somewhat theoretical integer overflow.
if (src->record_count > PREALLOC_MAX)
return NULL;
// Allocate and initialize a new Stream.
- index_stream *dest = index_stream_init(src->node.compressed_base,
+ dest = index_stream_init(src->node.compressed_base,
src->node.uncompressed_base, src->number,
src->block_number_base, allocator);
@@ -884,7 +907,7 @@ index_dup_stream(const index_stream *src, lzma_allocator *allocator)
// Allocate memory for the Records. We put all the Records into
// a single group. It's simplest and also tends to make
// lzma_index_locate() a little bit faster with very big Indexes.
- index_group *destg = lzma_alloc(sizeof(index_group)
+ destg = lzma_alloc(sizeof(index_group)
+ src->record_count * sizeof(index_record),
allocator);
if (destg == NULL) {
@@ -900,8 +923,7 @@ index_dup_stream(const index_stream *src, lzma_allocator *allocator)
destg->last = src->record_count - 1;
// Go through all the groups in src and copy the Records into destg.
- const index_group *srcg = (const index_group *)(src->groups.leftmost);
- size_t i = 0;
+ srcg = (index_group *)(src->groups.leftmost);
do {
memcpy(destg->records + i, srcg->records,
(srcg->last + 1) * sizeof(index_record));
@@ -921,6 +943,9 @@ index_dup_stream(const index_stream *src, lzma_allocator *allocator)
extern LZMA_API(lzma_index *)
lzma_index_dup(const lzma_index *src, lzma_allocator *allocator)
{
+ index_stream *srcstream;
+ index_stream *deststream;
+
// Allocate the base structure (no initial Stream).
lzma_index *dest = index_init_plain(allocator);
if (dest == NULL)
@@ -933,11 +958,9 @@ lzma_index_dup(const lzma_index *src, lzma_allocator *allocator)
dest->index_list_size = src->index_list_size;
// Copy the Streams and the groups in them.
- const index_stream *srcstream
- = (const index_stream *)(src->streams.leftmost);
+ srcstream = (index_stream *)(src->streams.leftmost);
do {
- index_stream *deststream = index_dup_stream(
- srcstream, allocator);
+ deststream = index_dup_stream(srcstream, allocator);
if (deststream == NULL) {
lzma_index_end(dest, allocator);
return NULL;
@@ -1096,14 +1119,19 @@ lzma_index_iter_rewind(lzma_index_iter *iter)
extern LZMA_API(lzma_bool)
lzma_index_iter_next(lzma_index_iter *iter, lzma_index_iter_mode mode)
{
+ const lzma_index *i;
+ const index_stream *stream;
+ const index_group *group;
+ size_t record;
+
// Catch unsupported mode values.
if ((unsigned int)(mode) > LZMA_INDEX_ITER_NONEMPTY_BLOCK)
return true;
- const lzma_index *i = iter->internal[ITER_INDEX].p;
- const index_stream *stream = iter->internal[ITER_STREAM].p;
- const index_group *group = NULL;
- size_t record = iter->internal[ITER_RECORD].s;
+ i = iter->internal[ITER_INDEX].p;
+ stream = iter->internal[ITER_STREAM].p;
+ group = NULL;
+ record = iter->internal[ITER_RECORD].s;
// If we are being asked for the next Stream, leave group to NULL
// so that the rest of the this function thinks that this Stream
@@ -1203,6 +1231,10 @@ again:
extern LZMA_API(lzma_bool)
lzma_index_iter_locate(lzma_index_iter *iter, lzma_vli target)
{
+ const index_stream *stream;
+ const index_group *group;
+ size_t left, right;
+
const lzma_index *i = iter->internal[ITER_INDEX].p;
// If the target is past the end of the file, return immediately.
@@ -1210,12 +1242,12 @@ lzma_index_iter_locate(lzma_index_iter *iter, lzma_vli target)
return true;
// Locate the Stream containing the target offset.
- const index_stream *stream = index_tree_locate(&i->streams, target);
+ stream = index_tree_locate(&i->streams, target);
assert(stream != NULL);
target -= stream->node.uncompressed_base;
// Locate the group containing the target offset.
- const index_group *group = index_tree_locate(&stream->groups, target);
+ group = index_tree_locate(&stream->groups, target);
assert(group != NULL);
// Use binary search to locate the exact Record. It is the first
@@ -1223,8 +1255,8 @@ lzma_index_iter_locate(lzma_index_iter *iter, lzma_vli target)
// This is because we want the rightmost Record that fullfills the
// search criterion. It is possible that there are empty Blocks;
// we don't want to return them.
- size_t left = 0;
- size_t right = group->last;
+ left = 0;
+ right = group->last;
while (left < right) {
const size_t pos = left + (right - left) / 2;
diff --git a/Utilities/cmliblzma/liblzma/common/index_decoder.c b/Utilities/cmliblzma/liblzma/common/index_decoder.c
index 83c8a3a..6c91f10 100644
--- a/Utilities/cmliblzma/liblzma/common/index_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/index_decoder.c
@@ -289,7 +289,7 @@ index_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern LZMA_API(lzma_ret)
lzma_index_decoder(lzma_stream *strm, lzma_index **i, uint64_t memlimit)
{
- lzma_next_strm_init(index_decoder_init, strm, i, memlimit);
+ lzma_next_strm_init2(index_decoder_init, strm, i, memlimit);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
@@ -303,21 +303,23 @@ lzma_index_buffer_decode(
lzma_index **i, uint64_t *memlimit, lzma_allocator *allocator,
const uint8_t *in, size_t *in_pos, size_t in_size)
{
+ lzma_coder coder;
+ lzma_ret ret;
+
+ // Store the input start position so that we can restore it in case
+ // of an error.
+ const size_t in_start = *in_pos;
+
// Sanity checks
if (i == NULL || memlimit == NULL
|| in == NULL || in_pos == NULL || *in_pos > in_size)
return LZMA_PROG_ERROR;
// Initialize the decoder.
- lzma_coder coder;
return_if_error(index_decoder_reset(&coder, allocator, i, *memlimit));
- // Store the input start position so that we can restore it in case
- // of an error.
- const size_t in_start = *in_pos;
-
// Do the actual decoding.
- lzma_ret ret = index_decode(&coder, allocator, in, in_pos, in_size,
+ ret = index_decode(&coder, allocator, in, in_pos, in_size,
NULL, NULL, 0, LZMA_RUN);
if (ret == LZMA_STREAM_END) {
diff --git a/Utilities/cmliblzma/liblzma/common/index_encoder.c b/Utilities/cmliblzma/liblzma/common/index_encoder.c
index 45919f0..a6f8598 100644
--- a/Utilities/cmliblzma/liblzma/common/index_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/index_encoder.c
@@ -207,7 +207,7 @@ lzma_index_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern LZMA_API(lzma_ret)
lzma_index_encoder(lzma_stream *strm, const lzma_index *i)
{
- lzma_next_strm_init(lzma_index_encoder_init, strm, i);
+ lzma_next_strm_init1(lzma_index_encoder_init, strm, i);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
@@ -220,6 +220,10 @@ extern LZMA_API(lzma_ret)
lzma_index_buffer_encode(const lzma_index *i,
uint8_t *out, size_t *out_pos, size_t out_size)
{
+ lzma_coder coder;
+ size_t out_start;
+ lzma_ret ret;
+
// Validate the arguments.
if (i == NULL || out == NULL || out_pos == NULL || *out_pos > out_size)
return LZMA_PROG_ERROR;
@@ -230,13 +234,12 @@ lzma_index_buffer_encode(const lzma_index *i,
// The Index encoder needs just one small data structure so we can
// allocate it on stack.
- lzma_coder coder;
index_encoder_reset(&coder, i);
// Do the actual encoding. This should never fail, but store
// the original *out_pos just in case.
- const size_t out_start = *out_pos;
- lzma_ret ret = index_encode(&coder, NULL, NULL, NULL, 0,
+ out_start = *out_pos;
+ ret = index_encode(&coder, NULL, NULL, NULL, 0,
out, out_pos, out_size, LZMA_RUN);
if (ret == LZMA_STREAM_END) {
diff --git a/Utilities/cmliblzma/liblzma/common/index_hash.c b/Utilities/cmliblzma/liblzma/common/index_hash.c
index e3e9386..0cf86b3 100644
--- a/Utilities/cmliblzma/liblzma/common/index_hash.c
+++ b/Utilities/cmliblzma/liblzma/common/index_hash.c
@@ -124,13 +124,14 @@ static lzma_ret
hash_append(lzma_index_hash_info *info, lzma_vli unpadded_size,
lzma_vli uncompressed_size)
{
+ const lzma_vli sizes[2] = { unpadded_size, uncompressed_size };
+
info->blocks_size += vli_ceil4(unpadded_size);
info->uncompressed_size += uncompressed_size;
info->index_list_size += lzma_vli_size(unpadded_size)
+ lzma_vli_size(uncompressed_size);
++info->count;
- const lzma_vli sizes[2] = { unpadded_size, uncompressed_size };
lzma_check_update(&info->check, LZMA_CHECK_BEST,
(const uint8_t *)(sizes), sizeof(sizes));
@@ -173,6 +174,9 @@ extern LZMA_API(lzma_ret)
lzma_index_hash_decode(lzma_index_hash *index_hash, const uint8_t *in,
size_t *in_pos, size_t in_size)
{
+ size_t in_start;
+ lzma_ret ret;
+
// Catch zero input buffer here, because in contrast to Index encoder
// and decoder functions, applications call this function directly
// instead of via lzma_code(), which does the buffer checking.
@@ -182,8 +186,8 @@ lzma_index_hash_decode(lzma_index_hash *index_hash, const uint8_t *in,
// NOTE: This function has many similarities to index_encode() and
// index_decode() functions found from index_encoder.c and
// index_decoder.c. See the comments especially in index_encoder.c.
- const size_t in_start = *in_pos;
- lzma_ret ret = LZMA_OK;
+ in_start = *in_pos;
+ ret = LZMA_OK;
while (*in_pos < in_size)
switch (index_hash->sequence) {
diff --git a/Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c b/Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c
index ae75315..9e2e1da 100644
--- a/Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c
@@ -19,6 +19,9 @@ lzma_stream_buffer_decode(uint64_t *memlimit, uint32_t flags,
const uint8_t *in, size_t *in_pos, size_t in_size,
uint8_t *out, size_t *out_pos, size_t out_size)
{
+ lzma_next_coder stream_decoder = LZMA_NEXT_CODER_INIT;
+ lzma_ret ret;
+
// Sanity checks
if (in_pos == NULL || (in == NULL && *in_pos != in_size)
|| *in_pos > in_size || out_pos == NULL
@@ -33,8 +36,7 @@ lzma_stream_buffer_decode(uint64_t *memlimit, uint32_t flags,
// Initialize the Stream decoder.
// TODO: We need something to tell the decoder that it can use the
// output buffer as workspace, and thus save significant amount of RAM.
- lzma_next_coder stream_decoder = LZMA_NEXT_CODER_INIT;
- lzma_ret ret = lzma_stream_decoder_init(
+ ret = lzma_stream_decoder_init(
&stream_decoder, allocator, *memlimit, flags);
if (ret == LZMA_OK) {
diff --git a/Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c b/Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c
index 2450ee2..8bca87f 100644
--- a/Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c
@@ -45,6 +45,10 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check,
lzma_allocator *allocator, const uint8_t *in, size_t in_size,
uint8_t *out, size_t *out_pos_ptr, size_t out_size)
{
+ lzma_stream_flags stream_flags = { 0 };
+ lzma_block block = { 0 };
+ size_t out_pos;
+
// Sanity checks
if (filters == NULL || (unsigned int)(check) > LZMA_CHECK_ID_MAX
|| (in == NULL && in_size != 0) || out == NULL
@@ -61,7 +65,7 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check,
// Use a local copy. We update *out_pos_ptr only if everything
// succeeds.
- size_t out_pos = *out_pos_ptr;
+ out_pos = *out_pos_ptr;
// Check that there's enough space for both Stream Header and
// Stream Footer.
@@ -73,10 +77,7 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check,
out_size -= LZMA_STREAM_HEADER_SIZE;
// Encode the Stream Header.
- lzma_stream_flags stream_flags = {
- .version = 0,
- .check = check,
- };
+ stream_flags.check = check;
if (lzma_stream_header_encode(&stream_flags, out + out_pos)
!= LZMA_OK)
@@ -85,11 +86,8 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check,
out_pos += LZMA_STREAM_HEADER_SIZE;
// Encode a Block but only if there is at least one byte of input.
- lzma_block block = {
- .version = 0,
- .check = check,
- .filters = filters,
- };
+ block.check = check;
+ block.filters = filters;
if (in_size > 0)
return_if_error(lzma_block_buffer_encode(&block, allocator,
@@ -97,6 +95,8 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check,
// Index
{
+ lzma_ret ret;
+
// Create an Index. It will have one Record if there was
// at least one byte of input to encode. Otherwise the
// Index will be empty.
@@ -104,7 +104,7 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check,
if (i == NULL)
return LZMA_MEM_ERROR;
- lzma_ret ret = LZMA_OK;
+ ret = LZMA_OK;
if (in_size > 0)
ret = lzma_index_append(i, allocator,
diff --git a/Utilities/cmliblzma/liblzma/common/stream_decoder.c b/Utilities/cmliblzma/liblzma/common/stream_decoder.c
index 37ea71e..56a009b 100644
--- a/Utilities/cmliblzma/liblzma/common/stream_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/stream_decoder.c
@@ -106,6 +106,8 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
while (true)
switch (coder->sequence) {
case SEQ_STREAM_HEADER: {
+ lzma_ret ret;
+
// Copy the Stream Header to the internal buffer.
lzma_bufcpy(in, in_pos, in_size, coder->buffer, &coder->pos,
LZMA_STREAM_HEADER_SIZE);
@@ -117,7 +119,7 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
coder->pos = 0;
// Decode the Stream Header.
- const lzma_ret ret = lzma_stream_header_decode(
+ ret = lzma_stream_header_decode(
&coder->stream_flags, coder->buffer);
if (ret != LZMA_OK)
return ret == LZMA_FORMAT_ERROR && !coder->first_stream
@@ -154,6 +156,11 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
// Fall through
case SEQ_BLOCK_HEADER: {
+ lzma_filter filters[LZMA_FILTERS_MAX + 1];
+ uint64_t memusage;
+ lzma_ret ret;
+ size_t i;
+
if (*in_pos >= in_size)
return LZMA_OK;
@@ -188,7 +195,6 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
// Set up a buffer to hold the filter chain. Block Header
// decoder will initialize all members of this array so
// we don't need to do it here.
- lzma_filter filters[LZMA_FILTERS_MAX + 1];
coder->block_options.filters = filters;
// Decode the Block Header.
@@ -196,9 +202,7 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
allocator, coder->buffer));
// Check the memory usage limit.
- const uint64_t memusage = lzma_raw_decoder_memusage(filters);
- lzma_ret ret;
-
+ memusage = lzma_raw_decoder_memusage(filters);
if (memusage == UINT64_MAX) {
// One or more unknown Filter IDs.
ret = LZMA_OPTIONS_ERROR;
@@ -224,7 +228,7 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
// Free the allocated filter options since they are needed
// only to initialize the Block decoder.
- for (size_t i = 0; i < LZMA_FILTERS_MAX; ++i)
+ for (i = 0; i < LZMA_FILTERS_MAX; ++i)
lzma_free(filters[i].options, allocator);
coder->block_options.filters = NULL;
@@ -260,6 +264,8 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
}
case SEQ_INDEX: {
+ lzma_ret ret;
+
// If we don't have any input, don't call
// lzma_index_hash_decode() since it would return
// LZMA_BUF_ERROR, which we must not do here.
@@ -268,7 +274,7 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
// Decode the Index and compare it to the hash calculated
// from the sizes of the Blocks (if any).
- const lzma_ret ret = lzma_index_hash_decode(coder->index_hash,
+ ret = lzma_index_hash_decode(coder->index_hash,
in, in_pos, in_size);
if (ret != LZMA_STREAM_END)
return ret;
@@ -279,6 +285,9 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
// Fall through
case SEQ_STREAM_FOOTER: {
+ lzma_stream_flags footer_flags;
+ lzma_ret ret;
+
// Copy the Stream Footer to the internal buffer.
lzma_bufcpy(in, in_pos, in_size, coder->buffer, &coder->pos,
LZMA_STREAM_HEADER_SIZE);
@@ -292,8 +301,7 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
// Decode the Stream Footer. The decoder gives
// LZMA_FORMAT_ERROR if the magic bytes don't match,
// so convert that return code to LZMA_DATA_ERROR.
- lzma_stream_flags footer_flags;
- const lzma_ret ret = lzma_stream_footer_decode(
+ ret = lzma_stream_footer_decode(
&footer_flags, coder->buffer);
if (ret != LZMA_OK)
return ret == LZMA_FORMAT_ERROR
@@ -442,7 +450,7 @@ lzma_stream_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern LZMA_API(lzma_ret)
lzma_stream_decoder(lzma_stream *strm, uint64_t memlimit, uint32_t flags)
{
- lzma_next_strm_init(lzma_stream_decoder_init, strm, memlimit, flags);
+ lzma_next_strm_init2(lzma_stream_decoder_init, strm, memlimit, flags);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/stream_encoder.c b/Utilities/cmliblzma/liblzma/common/stream_encoder.c
index 97a7a23..e2f2e10 100644
--- a/Utilities/cmliblzma/liblzma/common/stream_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/stream_encoder.c
@@ -147,6 +147,8 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
}
case SEQ_BLOCK_ENCODE: {
+ lzma_vli unpadded_size;
+
static const lzma_action convert[4] = {
LZMA_RUN,
LZMA_SYNC_FLUSH,
@@ -162,7 +164,7 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
return ret;
// Add a new Index Record.
- const lzma_vli unpadded_size = lzma_block_unpadded_size(
+ unpadded_size = lzma_block_unpadded_size(
&coder->block_options);
assert(unpadded_size != 0);
return_if_error(lzma_index_append(coder->index, allocator,
@@ -174,6 +176,12 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
}
case SEQ_INDEX_ENCODE: {
+ const lzma_stream_flags stream_flags = {
+ 0,
+ lzma_index_size(coder->index),
+ coder->block_options.check,
+ };
+
// Call the Index encoder. It doesn't take any input, so
// those pointers can be NULL.
const lzma_ret ret = coder->index_encoder.code(
@@ -184,11 +192,6 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
return ret;
// Encode the Stream Footer into coder->buffer.
- const lzma_stream_flags stream_flags = {
- .version = 0,
- .backward_size = lzma_index_size(coder->index),
- .check = coder->block_options.check,
- };
if (lzma_stream_footer_encode(&stream_flags, coder->buffer)
!= LZMA_OK)
@@ -211,11 +214,13 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
static void
stream_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
{
+ size_t i;
+
lzma_next_end(&coder->block_encoder, allocator);
lzma_next_end(&coder->index_encoder, allocator);
lzma_index_end(coder->index, allocator);
- for (size_t i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i)
+ for (i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i)
lzma_free(coder->filters[i].options, allocator);
lzma_free(coder, allocator);
@@ -228,14 +233,18 @@ stream_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
const lzma_filter *filters,
const lzma_filter *reversed_filters)
{
+ size_t i;
+
if (coder->sequence <= SEQ_BLOCK_INIT) {
+ lzma_ret ret;
+
// There is no incomplete Block waiting to be finished,
// thus we can change the whole filter chain. Start by
// trying to initialize the Block encoder with the new
// chain. This way we detect if the chain is valid.
coder->block_encoder_is_initialized = false;
coder->block_options.filters = (lzma_filter *)(filters);
- const lzma_ret ret = block_encoder_init(coder, allocator);
+ ret = block_encoder_init(coder, allocator);
coder->block_options.filters = coder->filters;
if (ret != LZMA_OK)
return ret;
@@ -255,7 +264,7 @@ stream_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
}
// Free the copy of the old chain and make a copy of the new chain.
- for (size_t i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i)
+ for (i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i)
lzma_free(coder->filters[i].options, allocator);
return lzma_filters_copy(filters, coder->filters, allocator);
@@ -266,6 +275,8 @@ extern lzma_ret
lzma_stream_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
const lzma_filter *filters, lzma_check check)
{
+ lzma_stream_flags stream_flags = { 0, 0, check };
+
lzma_next_coder_init(&lzma_stream_encoder_init, next, allocator);
if (filters == NULL)
@@ -298,10 +309,6 @@ lzma_stream_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
return LZMA_MEM_ERROR;
// Encode the Stream Header
- lzma_stream_flags stream_flags = {
- .version = 0,
- .check = check,
- };
return_if_error(lzma_stream_header_encode(
&stream_flags, next->coder->buffer));
@@ -320,7 +327,7 @@ extern LZMA_API(lzma_ret)
lzma_stream_encoder(lzma_stream *strm,
const lzma_filter *filters, lzma_check check)
{
- lzma_next_strm_init(lzma_stream_encoder_init, strm, filters, check);
+ lzma_next_strm_init2(lzma_stream_encoder_init, strm, filters, check);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c b/Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c
index 1bc2f97..8cf48a4 100644
--- a/Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c
@@ -30,13 +30,15 @@ stream_flags_decode(lzma_stream_flags *options, const uint8_t *in)
extern LZMA_API(lzma_ret)
lzma_stream_header_decode(lzma_stream_flags *options, const uint8_t *in)
{
+ uint32_t crc;
+
// Magic
if (memcmp(in, lzma_header_magic, sizeof(lzma_header_magic)) != 0)
return LZMA_FORMAT_ERROR;
// Verify the CRC32 so we can distinguish between corrupt
// and unsupported files.
- const uint32_t crc = lzma_crc32(in + sizeof(lzma_header_magic),
+ crc = lzma_crc32(in + sizeof(lzma_header_magic),
LZMA_STREAM_FLAGS_SIZE, 0);
if (crc != unaligned_read32le(in + sizeof(lzma_header_magic)
+ LZMA_STREAM_FLAGS_SIZE))
@@ -59,13 +61,15 @@ lzma_stream_header_decode(lzma_stream_flags *options, const uint8_t *in)
extern LZMA_API(lzma_ret)
lzma_stream_footer_decode(lzma_stream_flags *options, const uint8_t *in)
{
+ uint32_t crc;
+
// Magic
if (memcmp(in + sizeof(uint32_t) * 2 + LZMA_STREAM_FLAGS_SIZE,
lzma_footer_magic, sizeof(lzma_footer_magic)) != 0)
return LZMA_FORMAT_ERROR;
// CRC32
- const uint32_t crc = lzma_crc32(in + sizeof(uint32_t),
+ crc = lzma_crc32(in + sizeof(uint32_t),
sizeof(uint32_t) + LZMA_STREAM_FLAGS_SIZE, 0);
if (crc != unaligned_read32le(in))
return LZMA_DATA_ERROR;
diff --git a/Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c b/Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c
index 4e71715..290339e 100644
--- a/Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c
@@ -29,6 +29,8 @@ stream_flags_encode(const lzma_stream_flags *options, uint8_t *out)
extern LZMA_API(lzma_ret)
lzma_stream_header_encode(const lzma_stream_flags *options, uint8_t *out)
{
+ uint32_t crc;
+
assert(sizeof(lzma_header_magic) + LZMA_STREAM_FLAGS_SIZE
+ 4 == LZMA_STREAM_HEADER_SIZE);
@@ -43,7 +45,7 @@ lzma_stream_header_encode(const lzma_stream_flags *options, uint8_t *out)
return LZMA_PROG_ERROR;
// CRC32 of the Stream Header
- const uint32_t crc = lzma_crc32(out + sizeof(lzma_header_magic),
+ crc = lzma_crc32(out + sizeof(lzma_header_magic),
LZMA_STREAM_FLAGS_SIZE, 0);
unaligned_write32le(out + sizeof(lzma_header_magic)
@@ -56,6 +58,8 @@ lzma_stream_header_encode(const lzma_stream_flags *options, uint8_t *out)
extern LZMA_API(lzma_ret)
lzma_stream_footer_encode(const lzma_stream_flags *options, uint8_t *out)
{
+ uint32_t crc;
+
assert(2 * 4 + LZMA_STREAM_FLAGS_SIZE + sizeof(lzma_footer_magic)
== LZMA_STREAM_HEADER_SIZE);
@@ -73,7 +77,7 @@ lzma_stream_footer_encode(const lzma_stream_flags *options, uint8_t *out)
return LZMA_PROG_ERROR;
// CRC32
- const uint32_t crc = lzma_crc32(
+ crc = lzma_crc32(
out + 4, 4 + LZMA_STREAM_FLAGS_SIZE, 0);
unaligned_write32le(out, crc);
diff --git a/Utilities/cmliblzma/liblzma/common/vli_size.c b/Utilities/cmliblzma/liblzma/common/vli_size.c
index ec1b4fa..8b931e4 100644
--- a/Utilities/cmliblzma/liblzma/common/vli_size.c
+++ b/Utilities/cmliblzma/liblzma/common/vli_size.c
@@ -16,10 +16,11 @@
extern LZMA_API(uint32_t)
lzma_vli_size(lzma_vli vli)
{
+ uint32_t i = 0;
+
if (vli > LZMA_VLI_MAX)
return 0;
- uint32_t i = 0;
do {
vli >>= 7;
++i;