diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2007-12-09 17:06:45 +0200 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2007-12-09 17:06:45 +0200 |
commit | 07ac881779a8477f2c1ab112b91a129e24aa743c (patch) | |
tree | fe7f62c63b22b5942c4556ff56125cd0330129e2 /src/liblzma/subblock | |
parent | Added a bunch of .lzma test files. (diff) | |
download | xz-07ac881779a8477f2c1ab112b91a129e24aa743c.tar.xz |
Take advantage of return_if_error() macro in more places.
Cleaned Subblock filter's initialization code too.
Diffstat (limited to 'src/liblzma/subblock')
-rw-r--r-- | src/liblzma/subblock/subblock_decoder.c | 33 | ||||
-rw-r--r-- | src/liblzma/subblock/subblock_encoder.c | 45 |
2 files changed, 24 insertions, 54 deletions
diff --git a/src/liblzma/subblock/subblock_decoder.c b/src/liblzma/subblock/subblock_decoder.c index e0a46f45..5895242e 100644 --- a/src/liblzma/subblock/subblock_decoder.c +++ b/src/liblzma/subblock/subblock_decoder.c @@ -224,11 +224,9 @@ decode_buffer(lzma_coder *coder, lzma_allocator *allocator, return LZMA_DATA_ERROR; 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, - allocator, &coder->filter_flags); - if (ret != LZMA_OK) - return ret; + allocator, &coder->filter_flags)); coder->got_output_with_subfilter = false; @@ -491,7 +489,7 @@ decode_buffer(lzma_coder *coder, lzma_allocator *allocator, } 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, in, in_pos, in_size, NULL, NULL, 0, LZMA_RUN); if (ret != LZMA_STREAM_END) @@ -528,10 +526,9 @@ decode_buffer(lzma_coder *coder, lzma_allocator *allocator, if (filters[0].id == LZMA_FILTER_LZMA) filters[1].id = LZMA_VLI_VALUE_UNKNOWN; - ret = lzma_raw_decoder_init(&coder->subfilter, allocator, - filters, LZMA_VLI_VALUE_UNKNOWN, false); - if (ret != LZMA_OK) - return ret; + return_if_error(lzma_raw_decoder_init( + &coder->subfilter, allocator, + filters, LZMA_VLI_VALUE_UNKNOWN, false)); coder->sequence = SEQ_FLAGS; break; @@ -640,6 +637,9 @@ lzma_subblock_decoder_init(lzma_next_coder *next, lzma_allocator *allocator, if (next->coder == NULL) return LZMA_MEM_ERROR; + next->code = &subblock_decode; + next->end = &subblock_decoder_end; + next->coder->next = LZMA_NEXT_CODER_INIT; next->coder->subfilter = 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 next->coder->allow_subfilters = false; - { - const lzma_ret ret = lzma_next_filter_init(&next->coder->next, - 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; + return lzma_next_filter_init( + &next->coder->next, allocator, filters + 1); } diff --git a/src/liblzma/subblock/subblock_encoder.c b/src/liblzma/subblock/subblock_encoder.c index 9fa95b24..0987df96 100644 --- a/src/liblzma/subblock/subblock_encoder.c +++ b/src/liblzma/subblock/subblock_encoder.c @@ -295,13 +295,10 @@ subblock_buffer(lzma_coder *coder, lzma_allocator *allocator, // Grab the new Subblock Data Size and reallocate the buffer. if (coder->subblock.size == 0 && coder->options != NULL && coder->options->subblock_data_size - != coder->subblock.limit) { - const lzma_ret ret = subblock_data_size(coder, + != coder->subblock.limit) + return_if_error(subblock_data_size(coder, allocator, coder->options - ->subblock_data_size); - if (ret != LZMA_OK) - return ret; - } + ->subblock_data_size)); if (coder->subfilter.mode == SUB_NONE) { 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[1].id = LZMA_VLI_VALUE_UNKNOWN; - lzma_ret ret = lzma_raw_encoder_init( + return_if_error(lzma_raw_encoder_init( &coder->subfilter.subcoder, allocator, - options, LZMA_VLI_VALUE_UNKNOWN, false); - if (ret != LZMA_OK) - return ret; + options, LZMA_VLI_VALUE_UNKNOWN, false)); // Encode the Filter Flags field into a buffer. This should // never fail since we have already successfully initialized // the Subfilter itself. Check it still, and return // 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); assert(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) return LZMA_MEM_ERROR; + next->code = &subblock_encode; + next->end = &subblock_encoder_end; + next->coder->next = LZMA_NEXT_CODER_INIT; next->coder->subblock.data = NULL; 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; } - { - const lzma_ret ret = subblock_data_size(next->coder, allocator, - subblock_size_limit); - if (ret != LZMA_OK) { - subblock_encoder_end(next->coder, allocator); - return ret; - } - } - - { - const lzma_ret ret = lzma_next_filter_init(&next->coder->next, - allocator, filters + 1); - if (ret != LZMA_OK) { - subblock_encoder_end(next->coder, allocator); - return ret; - } - } + return_if_error(subblock_data_size(next->coder, allocator, + subblock_size_limit)); - next->code = &subblock_encode; - next->end = &subblock_encoder_end; - - return LZMA_OK; + return lzma_next_filter_init( + &next->coder->next, allocator, filters + 1); } |