1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

Take advantage of return_if_error() macro in more places.

Cleaned Subblock filter's initialization code too.
This commit is contained in:
Lasse Collin 2007-12-09 17:06:45 +02:00
parent 4133871796
commit 07ac881779
7 changed files with 63 additions and 138 deletions

View file

@ -343,12 +343,7 @@ lzma_block_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
|| options->has_backward_size))) || options->has_backward_size)))
return LZMA_PROG_ERROR; return LZMA_PROG_ERROR;
{ return_if_error(lzma_check_init(&next->coder->check, options->check));
const lzma_ret ret = lzma_check_init(
&next->coder->check, options->check);
if (ret != LZMA_OK)
return ret;
}
if (!options->has_eopm && options->uncompressed_size == 0) { if (!options->has_eopm && options->uncompressed_size == 0) {
if (!is_size_valid(0, options->compressed_size)) if (!is_size_valid(0, options->compressed_size))
@ -366,16 +361,11 @@ lzma_block_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
next->coder->sequence = SEQ_CODE; next->coder->sequence = SEQ_CODE;
} }
{ return_if_error(lzma_raw_decoder_init(&next->coder->next, allocator,
const lzma_ret ret = lzma_raw_decoder_init( options->filters, options->has_eopm
&next->coder->next, allocator, ? LZMA_VLI_VALUE_UNKNOWN
options->filters, options->has_eopm : options->uncompressed_size,
? LZMA_VLI_VALUE_UNKNOWN true));
: options->uncompressed_size,
true);
if (ret != LZMA_OK)
return ret;
}
next->coder->options = options; next->coder->options = options;
next->coder->pos = 0; next->coder->pos = 0;

View file

@ -179,14 +179,8 @@ delta_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
memzero(next->coder->history, LZMA_DELTA_DISTANCE_MAX); memzero(next->coder->history, LZMA_DELTA_DISTANCE_MAX);
// Initialize the next decoder in the chain, if any. // Initialize the next decoder in the chain, if any.
{ return lzma_next_filter_init(&next->coder->next,
const lzma_ret ret = lzma_next_filter_init(&next->coder->next,
allocator, filters + 1); allocator, filters + 1);
if (ret != LZMA_OK)
return ret;
}
return LZMA_OK;
} }

View file

@ -141,14 +141,11 @@ metadata_init(lzma_coder *coder, lzma_allocator *allocator)
static lzma_ret static lzma_ret
data_init(lzma_coder *coder, lzma_allocator *allocator) data_init(lzma_coder *coder, lzma_allocator *allocator)
{ {
lzma_ret ret = lzma_info_iter_next(&coder->iter, allocator); return_if_error(lzma_info_iter_next(&coder->iter, allocator));
if (ret != LZMA_OK)
return ret;
ret = lzma_info_iter_set(&coder->iter, LZMA_VLI_VALUE_UNKNOWN, return_if_error(lzma_info_iter_set(
coder->block_options.uncompressed_size); &coder->iter, LZMA_VLI_VALUE_UNKNOWN,
if (ret != LZMA_OK) coder->block_options.uncompressed_size));
return ret;
coder->block_options.total_size = coder->iter.total_size; coder->block_options.total_size = coder->iter.total_size;
coder->block_options.uncompressed_size = coder->iter.uncompressed_size; coder->block_options.uncompressed_size = coder->iter.uncompressed_size;
@ -207,11 +204,9 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
coder->block_options.check = coder->header_flags.check; coder->block_options.check = coder->header_flags.check;
coder->block_options.has_crc32 = coder->header_flags.has_crc32; coder->block_options.has_crc32 = coder->header_flags.has_crc32;
const lzma_ret ret = lzma_block_header_decoder_init( return_if_error(lzma_block_header_decoder_init(
&coder->block_header_decoder, allocator, &coder->block_header_decoder, allocator,
&coder->block_options); &coder->block_options));
if (ret != LZMA_OK)
return ret;
coder->sequence = SEQ_BLOCK_HEADER_CODE; coder->sequence = SEQ_BLOCK_HEADER_CODE;
} }

View file

@ -108,18 +108,15 @@ block_header_encode(lzma_coder *coder, lzma_allocator *allocator,
coder->info, type == BLOCK_HEADER_METADATA); coder->info, type == BLOCK_HEADER_METADATA);
} }
lzma_ret ret = lzma_block_header_size(&coder->block_options); return_if_error(lzma_block_header_size(&coder->block_options));
if (ret != LZMA_OK)
return ret;
coder->header_size = coder->block_options.header_size; coder->header_size = coder->block_options.header_size;
coder->header = lzma_alloc(coder->header_size, allocator); coder->header = lzma_alloc(coder->header_size, allocator);
if (coder->header == NULL) if (coder->header == NULL)
return LZMA_MEM_ERROR; return LZMA_MEM_ERROR;
ret = lzma_block_header_encode(coder->header, &coder->block_options); return_if_error(lzma_block_header_encode(
if (ret != LZMA_OK) coder->header, &coder->block_options));
return ret;
coder->header_pos = 0; coder->header_pos = 0;
return LZMA_OK; return LZMA_OK;
@ -130,18 +127,15 @@ static lzma_ret
metadata_encoder_init(lzma_coder *coder, lzma_allocator *allocator, metadata_encoder_init(lzma_coder *coder, lzma_allocator *allocator,
lzma_metadata *metadata, block_type type) lzma_metadata *metadata, block_type type)
{ {
lzma_ret ret = lzma_info_metadata_set(coder->info, allocator, return_if_error(lzma_info_metadata_set(coder->info, allocator,
metadata, type == BLOCK_HEADER_METADATA, false); metadata, type == BLOCK_HEADER_METADATA, false));
if (ret != LZMA_OK)
return ret;
const lzma_vli metadata_size = lzma_metadata_size(metadata); const lzma_vli metadata_size = lzma_metadata_size(metadata);
if (metadata_size == 0) if (metadata_size == 0)
return LZMA_PROG_ERROR; return LZMA_PROG_ERROR;
ret = block_header_encode(coder, allocator, metadata_size, type); return_if_error(block_header_encode(
if (ret != LZMA_OK) coder, allocator, metadata_size, type));
return ret;
return lzma_metadata_encoder_init(&coder->next, allocator, return lzma_metadata_encoder_init(&coder->next, allocator,
&coder->block_options, metadata); &coder->block_options, metadata);
@ -151,14 +145,10 @@ metadata_encoder_init(lzma_coder *coder, lzma_allocator *allocator,
static lzma_ret static lzma_ret
data_encoder_init(lzma_coder *coder, lzma_allocator *allocator) data_encoder_init(lzma_coder *coder, lzma_allocator *allocator)
{ {
lzma_ret ret = lzma_info_iter_next(&coder->iter, allocator); return_if_error(lzma_info_iter_next(&coder->iter, allocator));
if (ret != LZMA_OK)
return ret;
ret = block_header_encode(coder, allocator, return_if_error(block_header_encode(coder, allocator,
LZMA_VLI_VALUE_UNKNOWN, BLOCK_DATA); LZMA_VLI_VALUE_UNKNOWN, BLOCK_DATA));
if (ret != LZMA_OK)
return ret;
return lzma_block_encoder_init(&coder->next, allocator, return lzma_block_encoder_init(&coder->next, allocator,
&coder->block_options); &coder->block_options);
@ -233,10 +223,8 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
.extra = coder->stream_options->header, .extra = coder->stream_options->header,
}; };
const lzma_ret ret = metadata_encoder_init(coder, allocator, return_if_error(metadata_encoder_init(coder, allocator,
&metadata, BLOCK_HEADER_METADATA); &metadata, BLOCK_HEADER_METADATA));
if (ret != LZMA_OK)
return ret;
coder->sequence = SEQ_HEADER_METADATA_COPY; coder->sequence = SEQ_HEADER_METADATA_COPY;
break; break;
@ -253,10 +241,8 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
.extra = coder->stream_options->footer, .extra = coder->stream_options->footer,
}; };
const lzma_ret ret = metadata_encoder_init(coder, allocator, return_if_error(metadata_encoder_init(coder, allocator,
&metadata, BLOCK_FOOTER_METADATA); &metadata, BLOCK_FOOTER_METADATA));
if (ret != LZMA_OK)
return ret;
coder->sequence = SEQ_FOOTER_METADATA_COPY; coder->sequence = SEQ_FOOTER_METADATA_COPY;
break; break;
@ -265,19 +251,17 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
case SEQ_HEADER_METADATA_CODE: case SEQ_HEADER_METADATA_CODE:
case SEQ_FOOTER_METADATA_CODE: { case SEQ_FOOTER_METADATA_CODE: {
size_t dummy = 0; size_t dummy = 0;
lzma_ret ret = coder->next.code(coder->next.coder, const lzma_ret ret = coder->next.code(coder->next.coder,
allocator, NULL, &dummy, 0, allocator, NULL, &dummy, 0,
out, out_pos, out_size, LZMA_RUN); out, out_pos, out_size, LZMA_RUN);
if (ret != LZMA_STREAM_END) if (ret != LZMA_STREAM_END)
return ret; return ret;
ret = lzma_info_size_set(coder->info, return_if_error(lzma_info_size_set(coder->info,
coder->sequence == SEQ_HEADER_METADATA_CODE coder->sequence == SEQ_HEADER_METADATA_CODE
? LZMA_INFO_HEADER_METADATA ? LZMA_INFO_HEADER_METADATA
: LZMA_INFO_FOOTER_METADATA, : LZMA_INFO_FOOTER_METADATA,
coder->block_options.total_size); coder->block_options.total_size));
if (ret != LZMA_OK)
return ret;
++coder->sequence; ++coder->sequence;
break; break;
@ -299,9 +283,7 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
} }
} }
const lzma_ret ret = data_encoder_init(coder, allocator); return_if_error(data_encoder_init(coder, allocator));
if (ret != LZMA_OK)
return ret;
coder->sequence = SEQ_DATA_COPY; coder->sequence = SEQ_DATA_COPY;
break; break;
@ -315,17 +297,15 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
LZMA_FINISH, LZMA_FINISH,
}; };
lzma_ret ret = coder->next.code(coder->next.coder, const lzma_ret ret = coder->next.code(coder->next.coder,
allocator, in, in_pos, in_size, allocator, in, in_pos, in_size,
out, out_pos, out_size, convert[action]); out, out_pos, out_size, convert[action]);
if (ret != LZMA_STREAM_END || action == LZMA_SYNC_FLUSH) if (ret != LZMA_STREAM_END || action == LZMA_SYNC_FLUSH)
return ret; return ret;
ret = lzma_info_iter_set(&coder->iter, return_if_error(lzma_info_iter_set(&coder->iter,
coder->block_options.total_size, coder->block_options.total_size,
coder->block_options.uncompressed_size); coder->block_options.uncompressed_size));
if (ret != LZMA_OK)
return ret;
coder->sequence = SEQ_DATA_INIT; coder->sequence = SEQ_DATA_INIT;
break; break;
@ -344,10 +324,8 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
if (coder->header == NULL) if (coder->header == NULL)
return LZMA_MEM_ERROR; return LZMA_MEM_ERROR;
const lzma_ret ret = lzma_stream_tail_encode( return_if_error(lzma_stream_tail_encode(
coder->header, &flags); coder->header, &flags));
if (ret != LZMA_OK)
return ret;
coder->header_size = LZMA_STREAM_TAIL_SIZE; coder->header_size = LZMA_STREAM_TAIL_SIZE;
coder->header_pos = 0; coder->header_pos = 0;

View file

@ -71,7 +71,7 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
break; break;
case SEQ_DATA: { case SEQ_DATA: {
lzma_ret ret = coder->block_encoder.code( const lzma_ret ret = coder->block_encoder.code(
coder->block_encoder.coder, allocator, coder->block_encoder.coder, allocator,
in, in_pos, in_size, in, in_pos, in_size,
out, out_pos, out_size, action); out, out_pos, out_size, action);
@ -83,10 +83,8 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
assert(coder->header_size >= LZMA_STREAM_TAIL_SIZE); assert(coder->header_size >= LZMA_STREAM_TAIL_SIZE);
coder->header_size = LZMA_STREAM_TAIL_SIZE; coder->header_size = LZMA_STREAM_TAIL_SIZE;
ret = lzma_stream_tail_encode( return_if_error(lzma_stream_tail_encode(
coder->header, &coder->stream_flags); coder->header, &coder->stream_flags));
if (ret != LZMA_OK)
return ret;
coder->sequence = SEQ_FOOTER; coder->sequence = SEQ_FOOTER;
break; break;

View file

@ -224,11 +224,9 @@ decode_buffer(lzma_coder *coder, lzma_allocator *allocator,
return LZMA_DATA_ERROR; return LZMA_DATA_ERROR;
assert(coder->filter_flags.options == NULL); assert(coder->filter_flags.options == NULL);
const lzma_ret ret = lzma_filter_flags_decoder_init( return_if_error(lzma_filter_flags_decoder_init(
&coder->filter_flags_decoder, &coder->filter_flags_decoder,
allocator, &coder->filter_flags); allocator, &coder->filter_flags));
if (ret != LZMA_OK)
return ret;
coder->got_output_with_subfilter = false; coder->got_output_with_subfilter = false;
@ -491,7 +489,7 @@ decode_buffer(lzma_coder *coder, lzma_allocator *allocator,
} }
case SEQ_FILTER_FLAGS: { case SEQ_FILTER_FLAGS: {
lzma_ret ret = coder->filter_flags_decoder.code( const lzma_ret ret = coder->filter_flags_decoder.code(
coder->filter_flags_decoder.coder, allocator, coder->filter_flags_decoder.coder, allocator,
in, in_pos, in_size, NULL, NULL, 0, LZMA_RUN); in, in_pos, in_size, NULL, NULL, 0, LZMA_RUN);
if (ret != LZMA_STREAM_END) if (ret != LZMA_STREAM_END)
@ -528,10 +526,9 @@ decode_buffer(lzma_coder *coder, lzma_allocator *allocator,
if (filters[0].id == LZMA_FILTER_LZMA) if (filters[0].id == LZMA_FILTER_LZMA)
filters[1].id = LZMA_VLI_VALUE_UNKNOWN; filters[1].id = LZMA_VLI_VALUE_UNKNOWN;
ret = lzma_raw_decoder_init(&coder->subfilter, allocator, return_if_error(lzma_raw_decoder_init(
filters, LZMA_VLI_VALUE_UNKNOWN, false); &coder->subfilter, allocator,
if (ret != LZMA_OK) filters, LZMA_VLI_VALUE_UNKNOWN, false));
return ret;
coder->sequence = SEQ_FLAGS; coder->sequence = SEQ_FLAGS;
break; break;
@ -640,6 +637,9 @@ lzma_subblock_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
if (next->coder == NULL) if (next->coder == NULL)
return LZMA_MEM_ERROR; return LZMA_MEM_ERROR;
next->code = &subblock_decode;
next->end = &subblock_decoder_end;
next->coder->next = LZMA_NEXT_CODER_INIT; next->coder->next = LZMA_NEXT_CODER_INIT;
next->coder->subfilter = LZMA_NEXT_CODER_INIT; next->coder->subfilter = LZMA_NEXT_CODER_INIT;
next->coder->filter_flags_decoder = LZMA_NEXT_CODER_INIT; next->coder->filter_flags_decoder = LZMA_NEXT_CODER_INIT;
@ -665,17 +665,6 @@ lzma_subblock_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
else else
next->coder->allow_subfilters = false; next->coder->allow_subfilters = false;
{ return lzma_next_filter_init(
const lzma_ret ret = lzma_next_filter_init(&next->coder->next, &next->coder->next, allocator, filters + 1);
allocator, filters + 1);
if (ret != LZMA_OK) {
subblock_decoder_end(next->coder, allocator);
return ret;
}
}
next->code = &subblock_decode;
next->end = &subblock_decoder_end;
return LZMA_OK;
} }

View file

@ -295,13 +295,10 @@ subblock_buffer(lzma_coder *coder, lzma_allocator *allocator,
// Grab the new Subblock Data Size and reallocate the buffer. // Grab the new Subblock Data Size and reallocate the buffer.
if (coder->subblock.size == 0 && coder->options != NULL if (coder->subblock.size == 0 && coder->options != NULL
&& coder->options->subblock_data_size && coder->options->subblock_data_size
!= coder->subblock.limit) { != coder->subblock.limit)
const lzma_ret ret = subblock_data_size(coder, return_if_error(subblock_data_size(coder,
allocator, coder->options allocator, coder->options
->subblock_data_size); ->subblock_data_size));
if (ret != LZMA_OK)
return ret;
}
if (coder->subfilter.mode == SUB_NONE) { if (coder->subfilter.mode == SUB_NONE) {
assert(coder->subfilter.subcoder.code == NULL); assert(coder->subfilter.subcoder.code == NULL);
@ -638,17 +635,15 @@ subblock_buffer(lzma_coder *coder, lzma_allocator *allocator,
options[0] = coder->options->subfilter_options; options[0] = coder->options->subfilter_options;
options[1].id = LZMA_VLI_VALUE_UNKNOWN; options[1].id = LZMA_VLI_VALUE_UNKNOWN;
lzma_ret ret = lzma_raw_encoder_init( return_if_error(lzma_raw_encoder_init(
&coder->subfilter.subcoder, allocator, &coder->subfilter.subcoder, allocator,
options, LZMA_VLI_VALUE_UNKNOWN, false); options, LZMA_VLI_VALUE_UNKNOWN, false));
if (ret != LZMA_OK)
return ret;
// Encode the Filter Flags field into a buffer. This should // Encode the Filter Flags field into a buffer. This should
// never fail since we have already successfully initialized // never fail since we have already successfully initialized
// the Subfilter itself. Check it still, and return // the Subfilter itself. Check it still, and return
// LZMA_PROG_ERROR instead of whatever the ret would say. // LZMA_PROG_ERROR instead of whatever the ret would say.
ret = lzma_filter_flags_size( lzma_ret ret = lzma_filter_flags_size(
&coder->subfilter.flags_size, options); &coder->subfilter.flags_size, options);
assert(ret == LZMA_OK); assert(ret == LZMA_OK);
if (ret != LZMA_OK) if (ret != LZMA_OK)
@ -769,6 +764,9 @@ lzma_subblock_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
if (next->coder == NULL) if (next->coder == NULL)
return LZMA_MEM_ERROR; return LZMA_MEM_ERROR;
next->code = &subblock_encode;
next->end = &subblock_encoder_end;
next->coder->next = LZMA_NEXT_CODER_INIT; next->coder->next = LZMA_NEXT_CODER_INIT;
next->coder->subblock.data = NULL; next->coder->subblock.data = NULL;
next->coder->subblock.limit = 0; next->coder->subblock.limit = 0;
@ -816,26 +814,9 @@ lzma_subblock_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
subblock_size_limit = LZMA_SUBBLOCK_DATA_SIZE_DEFAULT; subblock_size_limit = LZMA_SUBBLOCK_DATA_SIZE_DEFAULT;
} }
{ return_if_error(subblock_data_size(next->coder, allocator,
const lzma_ret ret = subblock_data_size(next->coder, allocator, subblock_size_limit));
subblock_size_limit);
if (ret != LZMA_OK) {
subblock_encoder_end(next->coder, allocator);
return ret;
}
}
{ return lzma_next_filter_init(
const lzma_ret ret = lzma_next_filter_init(&next->coder->next, &next->coder->next, allocator, filters + 1);
allocator, filters + 1);
if (ret != LZMA_OK) {
subblock_encoder_end(next->coder, allocator);
return ret;
}
}
next->code = &subblock_encode;
next->end = &subblock_encoder_end;
return LZMA_OK;
} }