diff options
author | mm <mm@FreeBSD.org> | 2011-07-11 14:15:27 +0000 |
---|---|---|
committer | mm <mm@FreeBSD.org> | 2011-07-11 14:15:27 +0000 |
commit | cf995996ab105668883720bd5e270c8494278403 (patch) | |
tree | a2cc3c1778f675303456a23d9922f0e98837006d /contrib/xz/src | |
parent | 6425e22b7b2564aacbf2900bc49405df8f170949 (diff) | |
parent | 0fa8e9ee27db12b75ce059f30a011de44966454f (diff) | |
download | FreeBSD-src-cf995996ab105668883720bd5e270c8494278403.zip FreeBSD-src-cf995996ab105668883720bd5e270c8494278403.tar.gz |
Update xz to git snapshot of v5.0 branch as of 20110711 (post-5.0.3)
For architectures with __NO_STRICT_ALIGNMENT
define TUKLIB_FAST_UNALIGNED_ACCESS
MFC after: 2 weeks
Diffstat (limited to 'contrib/xz/src')
42 files changed, 163 insertions, 119 deletions
diff --git a/contrib/xz/src/common/tuklib_open_stdxxx.c b/contrib/xz/src/common/tuklib_open_stdxxx.c index 08bc60d..26702a6 100644 --- a/contrib/xz/src/common/tuklib_open_stdxxx.c +++ b/contrib/xz/src/common/tuklib_open_stdxxx.c @@ -39,12 +39,14 @@ tuklib_open_stdxxx(int err_status) | (i == 0 ? O_WRONLY : O_RDONLY)); if (fd != i) { + if (fd != -1) + (void)close(fd); + // Something went wrong. Exit with the // exit status we were given. Don't try // to print an error message, since stderr // may very well be non-existent. This // error should be extremely rare. - (void)close(fd); exit(err_status); } } diff --git a/contrib/xz/src/liblzma/api/lzma/block.h b/contrib/xz/src/liblzma/api/lzma/block.h index 3019bf9..8a4bf23 100644 --- a/contrib/xz/src/liblzma/api/lzma/block.h +++ b/contrib/xz/src/liblzma/api/lzma/block.h @@ -483,6 +483,7 @@ extern LZMA_API(size_t) lzma_block_buffer_bound(size_t uncompressed_size) * * \return - LZMA_OK: Encoding was successful. * - LZMA_BUF_ERROR: Not enough output buffer space. + * - LZMA_UNSUPPORTED_CHECK * - LZMA_OPTIONS_ERROR * - LZMA_MEM_ERROR * - LZMA_DATA_ERROR diff --git a/contrib/xz/src/liblzma/api/lzma/container.h b/contrib/xz/src/liblzma/api/lzma/container.h index 83e70b4..7a9ffc6 100644 --- a/contrib/xz/src/liblzma/api/lzma/container.h +++ b/contrib/xz/src/liblzma/api/lzma/container.h @@ -66,6 +66,10 @@ * This function is a wrapper for lzma_raw_encoder_memusage(). * * \param preset Compression preset (level and possible flags) + * + * \return Number of bytes of memory required for the given + * preset when encoding. If an error occurs, for example + * due to unsupported preset, UINT64_MAX is returned. */ extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset) lzma_nothrow lzma_attr_pure; @@ -77,6 +81,11 @@ extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset) * This function is a wrapper for lzma_raw_decoder_memusage(). * * \param preset Compression preset (level and possible flags) + * + * \return Number of bytes of memory required to decompress a file + * that was compressed using the given preset. If an error + * occurs, for example due to unsupported preset, UINT64_MAX + * is returned. */ extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset) lzma_nothrow lzma_attr_pure; @@ -148,6 +157,7 @@ extern LZMA_API(lzma_ret) lzma_easy_encoder( * * \return - LZMA_OK: Encoding was successful. * - LZMA_BUF_ERROR: Not enough output buffer space. + * - LZMA_UNSUPPORTED_CHECK * - LZMA_OPTIONS_ERROR * - LZMA_MEM_ERROR * - LZMA_DATA_ERROR @@ -171,6 +181,7 @@ extern LZMA_API(lzma_ret) lzma_easy_buffer_encode( * * \return - LZMA_OK: Initialization was successful. * - LZMA_MEM_ERROR + * - LZMA_UNSUPPORTED_CHECK * - LZMA_OPTIONS_ERROR * - LZMA_PROG_ERROR */ @@ -250,6 +261,7 @@ extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size) * * \return - LZMA_OK: Encoding was successful. * - LZMA_BUF_ERROR: Not enough output buffer space. + * - LZMA_UNSUPPORTED_CHECK * - LZMA_OPTIONS_ERROR * - LZMA_MEM_ERROR * - LZMA_DATA_ERROR diff --git a/contrib/xz/src/liblzma/api/lzma/filter.h b/contrib/xz/src/liblzma/api/lzma/filter.h index efd036f..e0bc163 100644 --- a/contrib/xz/src/liblzma/api/lzma/filter.h +++ b/contrib/xz/src/liblzma/api/lzma/filter.h @@ -131,7 +131,9 @@ extern LZMA_API(lzma_ret) lzma_filters_copy(const lzma_filter *src, * .id == LZMA_VLI_UNKNOWN. * * \return Number of bytes of memory required for the given - * filter chain when encoding. + * filter chain when encoding. If an error occurs, + * for example due to unsupported filter chain, + * UINT64_MAX is returned. */ extern LZMA_API(uint64_t) lzma_raw_encoder_memusage(const lzma_filter *filters) lzma_nothrow lzma_attr_pure; @@ -148,7 +150,9 @@ extern LZMA_API(uint64_t) lzma_raw_encoder_memusage(const lzma_filter *filters) * .id == LZMA_VLI_UNKNOWN. * * \return Number of bytes of memory required for the given - * filter chain when decoding. + * filter chain when decoding. If an error occurs, + * for example due to unsupported filter chain, + * UINT64_MAX is returned. */ extern LZMA_API(uint64_t) lzma_raw_decoder_memusage(const lzma_filter *filters) lzma_nothrow lzma_attr_pure; diff --git a/contrib/xz/src/liblzma/api/lzma/version.h b/contrib/xz/src/liblzma/api/lzma/version.h index 43c211f..9226663 100644 --- a/contrib/xz/src/liblzma/api/lzma/version.h +++ b/contrib/xz/src/liblzma/api/lzma/version.h @@ -22,7 +22,7 @@ */ #define LZMA_VERSION_MAJOR 5 #define LZMA_VERSION_MINOR 0 -#define LZMA_VERSION_PATCH 1 +#define LZMA_VERSION_PATCH 3 #define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE #ifndef LZMA_VERSION_COMMIT diff --git a/contrib/xz/src/liblzma/common/alone_decoder.c b/contrib/xz/src/liblzma/common/alone_decoder.c index 039b428..678c79e 100644 --- a/contrib/xz/src/liblzma/common/alone_decoder.c +++ b/contrib/xz/src/liblzma/common/alone_decoder.c @@ -46,7 +46,7 @@ struct lzma_coder_s { static lzma_ret alone_decode(lzma_coder *coder, - lzma_allocator *allocator lzma_attribute((unused)), + lzma_allocator *allocator lzma_attribute((__unused__)), const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, diff --git a/contrib/xz/src/liblzma/common/alone_encoder.c b/contrib/xz/src/liblzma/common/alone_encoder.c index d8c0170..eb1697e 100644 --- a/contrib/xz/src/liblzma/common/alone_encoder.c +++ b/contrib/xz/src/liblzma/common/alone_encoder.c @@ -32,7 +32,7 @@ struct lzma_coder_s { static lzma_ret alone_encode(lzma_coder *coder, - lzma_allocator *allocator lzma_attribute((unused)), + lzma_allocator *allocator lzma_attribute((__unused__)), const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, @@ -103,7 +103,7 @@ alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator, if (options->dict_size < LZMA_DICT_SIZE_MIN) return LZMA_OPTIONS_ERROR; - // Round up to to the next 2^n or 2^n + 2^(n - 1) depending on which + // Round up to the next 2^n or 2^n + 2^(n - 1) depending on which // 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. diff --git a/contrib/xz/src/liblzma/common/block_buffer_encoder.c b/contrib/xz/src/liblzma/common/block_buffer_encoder.c index a8f71c2..519c6a6 100644 --- a/contrib/xz/src/liblzma/common/block_buffer_encoder.c +++ b/contrib/xz/src/liblzma/common/block_buffer_encoder.c @@ -226,16 +226,23 @@ 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) { - // Sanity checks - if (block == NULL || block->filters == NULL - || (in == NULL && in_size != 0) || out == NULL + // Validate the arguments. + if (block == NULL || (in == NULL && in_size != 0) || out == NULL || out_pos == NULL || *out_pos > out_size) return LZMA_PROG_ERROR; - // Check the version field. + // The contents of the structure may depend on the version so + // check the version before validating the contents of *block. if (block->version != 0) return LZMA_OPTIONS_ERROR; + if ((unsigned int)(block->check) > LZMA_CHECK_ID_MAX + || block->filters == NULL) + return LZMA_PROG_ERROR; + + if (!lzma_check_is_supported(block->check)) + return LZMA_UNSUPPORTED_CHECK; + // Size of a Block has to be a multiple of four, so limit the size // here already. This way we don't need to check it again when adding // Block Padding. @@ -243,8 +250,7 @@ lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator, // Get the size of the Check field. const size_t check_size = lzma_check_size(block->check); - if (check_size == UINT32_MAX) - return LZMA_PROG_ERROR; + assert(check_size != UINT32_MAX); // Reserve space for the Check field. if (out_size - *out_pos <= check_size) diff --git a/contrib/xz/src/liblzma/common/block_encoder.c b/contrib/xz/src/liblzma/common/block_encoder.c index ca51523..1eeb502 100644 --- a/contrib/xz/src/liblzma/common/block_encoder.c +++ b/contrib/xz/src/liblzma/common/block_encoder.c @@ -144,7 +144,7 @@ block_encoder_end(lzma_coder *coder, lzma_allocator *allocator) static lzma_ret block_encoder_update(lzma_coder *coder, lzma_allocator *allocator, - const lzma_filter *filters lzma_attribute((unused)), + const lzma_filter *filters lzma_attribute((__unused__)), const lzma_filter *reversed_filters) { if (coder->sequence != SEQ_CODE) @@ -161,6 +161,11 @@ lzma_block_encoder_init(lzma_next_coder *next, lzma_allocator *allocator, { lzma_next_coder_init(&lzma_block_encoder_init, next, allocator); + if (block == NULL) + return LZMA_PROG_ERROR; + + // The contents of the structure may depend on the version so + // check the version first. if (block->version != 0) return LZMA_OPTIONS_ERROR; diff --git a/contrib/xz/src/liblzma/common/common.c b/contrib/xz/src/liblzma/common/common.c index 0408e15..b9e3860 100644 --- a/contrib/xz/src/liblzma/common/common.c +++ b/contrib/xz/src/liblzma/common/common.c @@ -35,7 +35,7 @@ lzma_version_string(void) // Memory allocation // /////////////////////// -extern void * lzma_attribute((malloc)) +extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1) lzma_alloc(size_t size, lzma_allocator *allocator) { // Some malloc() variants return NULL if called with size == 0. diff --git a/contrib/xz/src/liblzma/common/common.h b/contrib/xz/src/liblzma/common/common.h index b819432..45aba4f 100644 --- a/contrib/xz/src/liblzma/common/common.h +++ b/contrib/xz/src/liblzma/common/common.h @@ -205,7 +205,7 @@ struct lzma_internal_s { /// Allocates memory extern void *lzma_alloc(size_t size, lzma_allocator *allocator) - lzma_attribute((malloc)) lzma_attr_alloc_size(1); + lzma_attribute((__malloc__)) lzma_attr_alloc_size(1); /// Frees memory extern void lzma_free(void *ptr, lzma_allocator *allocator); diff --git a/contrib/xz/src/liblzma/common/filter_common.c b/contrib/xz/src/liblzma/common/filter_common.c index b157c62..7c95b05 100644 --- a/contrib/xz/src/liblzma/common/filter_common.c +++ b/contrib/xz/src/liblzma/common/filter_common.c @@ -43,7 +43,7 @@ static const struct { .changes_size = true, }, #endif -#ifdef HAVE_DECODER_LZMA2 +#if defined(HAVE_ENCODER_LZMA2) || defined(HAVE_DECODER_LZMA2) { .id = LZMA_FILTER_LZMA2, .options_size = sizeof(lzma_options_lzma), @@ -52,7 +52,7 @@ static const struct { .changes_size = true, }, #endif -#ifdef HAVE_DECODER_X86 +#if defined(HAVE_ENCODER_X86) || defined(HAVE_DECODER_X86) { .id = LZMA_FILTER_X86, .options_size = sizeof(lzma_options_bcj), @@ -70,7 +70,7 @@ static const struct { .changes_size = false, }, #endif -#ifdef HAVE_DECODER_IA64 +#if defined(HAVE_ENCODER_IA64) || defined(HAVE_DECODER_IA64) { .id = LZMA_FILTER_IA64, .options_size = sizeof(lzma_options_bcj), diff --git a/contrib/xz/src/liblzma/common/index.c b/contrib/xz/src/liblzma/common/index.c index ddb9d36..9af4bc1 100644 --- a/contrib/xz/src/liblzma/common/index.c +++ b/contrib/xz/src/liblzma/common/index.c @@ -398,10 +398,13 @@ extern LZMA_API(lzma_index *) lzma_index_init(lzma_allocator *allocator) { lzma_index *i = index_init_plain(allocator); + if (i == NULL) + return NULL; + index_stream *s = index_stream_init(0, 0, 1, 0, allocator); - if (i == NULL || s == NULL) { - index_stream_end(s, allocator); + if (s == NULL) { lzma_free(i, allocator); + return NULL; } index_tree_append(&i->streams, &s->node); diff --git a/contrib/xz/src/liblzma/common/index_decoder.c b/contrib/xz/src/liblzma/common/index_decoder.c index a6bc650..83c8a3af 100644 --- a/contrib/xz/src/liblzma/common/index_decoder.c +++ b/contrib/xz/src/liblzma/common/index_decoder.c @@ -56,10 +56,11 @@ struct lzma_coder_s { static lzma_ret index_decode(lzma_coder *coder, lzma_allocator *allocator, const uint8_t *restrict in, size_t *restrict in_pos, - size_t in_size, uint8_t *restrict out lzma_attribute((unused)), - size_t *restrict out_pos lzma_attribute((unused)), - size_t out_size lzma_attribute((unused)), - lzma_action action lzma_attribute((unused))) + size_t in_size, + uint8_t *restrict out lzma_attribute((__unused__)), + size_t *restrict out_pos lzma_attribute((__unused__)), + size_t out_size lzma_attribute((__unused__)), + lzma_action action lzma_attribute((__unused__))) { // Similar optimization as in index_encoder.c const size_t in_start = *in_pos; diff --git a/contrib/xz/src/liblzma/common/index_encoder.c b/contrib/xz/src/liblzma/common/index_encoder.c index c10d7af..45919f0 100644 --- a/contrib/xz/src/liblzma/common/index_encoder.c +++ b/contrib/xz/src/liblzma/common/index_encoder.c @@ -42,12 +42,13 @@ struct lzma_coder_s { static lzma_ret index_encode(lzma_coder *coder, - lzma_allocator *allocator lzma_attribute((unused)), - const uint8_t *restrict in lzma_attribute((unused)), - size_t *restrict in_pos lzma_attribute((unused)), - size_t in_size lzma_attribute((unused)), + lzma_allocator *allocator lzma_attribute((__unused__)), + const uint8_t *restrict in lzma_attribute((__unused__)), + size_t *restrict in_pos lzma_attribute((__unused__)), + size_t in_size lzma_attribute((__unused__)), uint8_t *restrict out, size_t *restrict out_pos, - size_t out_size, lzma_action action lzma_attribute((unused))) + size_t out_size, + lzma_action action lzma_attribute((__unused__))) { // Position where to start calculating CRC32. The idea is that we // need to call lzma_crc32() only once per call to index_encode(). diff --git a/contrib/xz/src/liblzma/common/stream_buffer_encoder.c b/contrib/xz/src/liblzma/common/stream_buffer_encoder.c index f727d85..2450ee2 100644 --- a/contrib/xz/src/liblzma/common/stream_buffer_encoder.c +++ b/contrib/xz/src/liblzma/common/stream_buffer_encoder.c @@ -51,6 +51,9 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check, || out_pos_ptr == NULL || *out_pos_ptr > out_size) return LZMA_PROG_ERROR; + if (!lzma_check_is_supported(check)) + return LZMA_UNSUPPORTED_CHECK; + // Note for the paranoids: Index encoder prevents the Stream from // getting too big and still being accepted with LZMA_OK, and Block // encoder catches if the input is too big. So we don't need to @@ -81,26 +84,32 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check, out_pos += LZMA_STREAM_HEADER_SIZE; - // Block + // Encode a Block but only if there is at least one byte of input. lzma_block block = { .version = 0, .check = check, .filters = filters, }; - return_if_error(lzma_block_buffer_encode(&block, allocator, - in, in_size, out, &out_pos, out_size)); + if (in_size > 0) + return_if_error(lzma_block_buffer_encode(&block, allocator, + in, in_size, out, &out_pos, out_size)); // Index { - // Create an Index with one Record. + // 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. lzma_index *i = lzma_index_init(allocator); if (i == NULL) return LZMA_MEM_ERROR; - lzma_ret ret = lzma_index_append(i, allocator, - lzma_block_unpadded_size(&block), - block.uncompressed_size); + lzma_ret ret = LZMA_OK; + + if (in_size > 0) + ret = lzma_index_append(i, allocator, + lzma_block_unpadded_size(&block), + block.uncompressed_size); // If adding the Record was successful, encode the Index // and get its size which will be stored into Stream Footer. diff --git a/contrib/xz/src/liblzma/common/stream_encoder.c b/contrib/xz/src/liblzma/common/stream_encoder.c index 48d91da..97a7a23 100644 --- a/contrib/xz/src/liblzma/common/stream_encoder.c +++ b/contrib/xz/src/liblzma/common/stream_encoder.c @@ -280,6 +280,7 @@ lzma_stream_encoder_init(lzma_next_coder *next, lzma_allocator *allocator, next->end = &stream_encoder_end; next->update = &stream_encoder_update; + next->coder->filters[0].id = LZMA_VLI_UNKNOWN; next->coder->block_encoder = LZMA_NEXT_CODER_INIT; next->coder->index_encoder = LZMA_NEXT_CODER_INIT; next->coder->index = NULL; @@ -289,7 +290,6 @@ lzma_stream_encoder_init(lzma_next_coder *next, lzma_allocator *allocator, next->coder->sequence = SEQ_STREAM_HEADER; next->coder->block_options.version = 0; next->coder->block_options.check = check; - next->coder->filters[0].id = LZMA_VLI_UNKNOWN; // Initialize the Index lzma_index_end(next->coder->index, allocator); diff --git a/contrib/xz/src/liblzma/delta/delta_encoder.c b/contrib/xz/src/liblzma/delta/delta_encoder.c index ea1cc2c..15c7951 100644 --- a/contrib/xz/src/liblzma/delta/delta_encoder.c +++ b/contrib/xz/src/liblzma/delta/delta_encoder.c @@ -85,7 +85,7 @@ delta_encode(lzma_coder *coder, lzma_allocator *allocator, static lzma_ret delta_encoder_update(lzma_coder *coder, lzma_allocator *allocator, - const lzma_filter *filters_null lzma_attribute((unused)), + const lzma_filter *filters_null lzma_attribute((__unused__)), const lzma_filter *reversed_filters) { // Delta doesn't and will never support changing the options in diff --git a/contrib/xz/src/liblzma/lz/lz_decoder.c b/contrib/xz/src/liblzma/lz/lz_decoder.c index 2c57355..d74085c 100644 --- a/contrib/xz/src/liblzma/lz/lz_decoder.c +++ b/contrib/xz/src/liblzma/lz/lz_decoder.c @@ -126,7 +126,7 @@ decode_buffer(lzma_coder *coder, static lzma_ret lz_decode(lzma_coder *coder, - lzma_allocator *allocator lzma_attribute((unused)), + lzma_allocator *allocator lzma_attribute((__unused__)), const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, diff --git a/contrib/xz/src/liblzma/lz/lz_encoder.c b/contrib/xz/src/liblzma/lz/lz_encoder.c index 273f577..e240696 100644 --- a/contrib/xz/src/liblzma/lz/lz_encoder.c +++ b/contrib/xz/src/liblzma/lz/lz_encoder.c @@ -480,7 +480,7 @@ lz_encoder_end(lzma_coder *coder, lzma_allocator *allocator) static lzma_ret lz_encoder_update(lzma_coder *coder, lzma_allocator *allocator, - const lzma_filter *filters_null lzma_attribute((unused)), + const lzma_filter *filters_null lzma_attribute((__unused__)), const lzma_filter *reversed_filters) { if (coder->lz.options_update == NULL) diff --git a/contrib/xz/src/liblzma/lz/lz_encoder_hash.h b/contrib/xz/src/liblzma/lz/lz_encoder_hash.h index c398d7d..342a333 100644 --- a/contrib/xz/src/liblzma/lz/lz_encoder_hash.h +++ b/contrib/xz/src/liblzma/lz/lz_encoder_hash.h @@ -39,7 +39,7 @@ // Endianness doesn't matter in hash_2_calc() (no effect on the output). #ifdef TUKLIB_FAST_UNALIGNED_ACCESS # define hash_2_calc() \ - const uint32_t hash_value = *(const uint16_t *)(cur); + const uint32_t hash_value = *(const uint16_t *)(cur) #else # define hash_2_calc() \ const uint32_t hash_value \ diff --git a/contrib/xz/src/liblzma/lzma/lzma2_decoder.c b/contrib/xz/src/liblzma/lzma/lzma2_decoder.c index f38879c..3e42575 100644 --- a/contrib/xz/src/liblzma/lzma/lzma2_decoder.c +++ b/contrib/xz/src/liblzma/lzma/lzma2_decoder.c @@ -67,6 +67,10 @@ lzma2_decode(lzma_coder *restrict coder, lzma_dict *restrict dict, const uint32_t control = in[*in_pos]; ++*in_pos; + // End marker + if (control == 0x00) + return LZMA_STREAM_END; + if (control >= 0xE0 || control == 1) { // Dictionary reset implies that next LZMA chunk has // to set new properties. @@ -104,10 +108,6 @@ lzma2_decode(lzma_coder *restrict coder, lzma_dict *restrict dict, &coder->options); } } else { - // End marker - if (control == 0x00) - return LZMA_STREAM_END; - // Invalid control values if (control > 2) return LZMA_DATA_ERROR; diff --git a/contrib/xz/src/liblzma/lzma/lzma2_encoder.c b/contrib/xz/src/liblzma/lzma/lzma2_encoder.c index b48e0d6..992720c 100644 --- a/contrib/xz/src/liblzma/lzma/lzma2_encoder.c +++ b/contrib/xz/src/liblzma/lzma/lzma2_encoder.c @@ -374,7 +374,7 @@ lzma_lzma2_props_encode(const void *options, uint8_t *out) const lzma_options_lzma *const opt = options; uint32_t d = my_max(opt->dict_size, LZMA_DICT_SIZE_MIN); - // Round up to to the next 2^n - 1 or 2^n + 2^(n - 1) - 1 depending + // Round up to the next 2^n - 1 or 2^n + 2^(n - 1) - 1 depending // on which one is the next: --d; d |= d >> 2; diff --git a/contrib/xz/src/liblzma/simple/arm.c b/contrib/xz/src/liblzma/simple/arm.c index 8fcf643..a84702a 100644 --- a/contrib/xz/src/liblzma/simple/arm.c +++ b/contrib/xz/src/liblzma/simple/arm.c @@ -15,7 +15,7 @@ static size_t -arm_code(lzma_simple *simple lzma_attribute((unused)), +arm_code(lzma_simple *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size) { diff --git a/contrib/xz/src/liblzma/simple/armthumb.c b/contrib/xz/src/liblzma/simple/armthumb.c index eb6a69d..4b49175 100644 --- a/contrib/xz/src/liblzma/simple/armthumb.c +++ b/contrib/xz/src/liblzma/simple/armthumb.c @@ -15,7 +15,7 @@ static size_t -armthumb_code(lzma_simple *simple lzma_attribute((unused)), +armthumb_code(lzma_simple *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size) { diff --git a/contrib/xz/src/liblzma/simple/ia64.c b/contrib/xz/src/liblzma/simple/ia64.c index fd263d4..ce3692b 100644 --- a/contrib/xz/src/liblzma/simple/ia64.c +++ b/contrib/xz/src/liblzma/simple/ia64.c @@ -15,7 +15,7 @@ static size_t -ia64_code(lzma_simple *simple lzma_attribute((unused)), +ia64_code(lzma_simple *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size) { diff --git a/contrib/xz/src/liblzma/simple/powerpc.c b/contrib/xz/src/liblzma/simple/powerpc.c index aaa14f2..6f83511 100644 --- a/contrib/xz/src/liblzma/simple/powerpc.c +++ b/contrib/xz/src/liblzma/simple/powerpc.c @@ -15,7 +15,7 @@ static size_t -powerpc_code(lzma_simple *simple lzma_attribute((unused)), +powerpc_code(lzma_simple *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size) { diff --git a/contrib/xz/src/liblzma/simple/simple_coder.c b/contrib/xz/src/liblzma/simple/simple_coder.c index 06db86e..37de7fa 100644 --- a/contrib/xz/src/liblzma/simple/simple_coder.c +++ b/contrib/xz/src/liblzma/simple/simple_coder.c @@ -212,7 +212,7 @@ simple_coder_end(lzma_coder *coder, lzma_allocator *allocator) static lzma_ret simple_coder_update(lzma_coder *coder, lzma_allocator *allocator, - const lzma_filter *filters_null lzma_attribute((unused)), + const lzma_filter *filters_null lzma_attribute((__unused__)), const lzma_filter *reversed_filters) { // No update support, just call the next filter in the chain. diff --git a/contrib/xz/src/liblzma/simple/sparc.c b/contrib/xz/src/liblzma/simple/sparc.c index 808a59a..8270d6a 100644 --- a/contrib/xz/src/liblzma/simple/sparc.c +++ b/contrib/xz/src/liblzma/simple/sparc.c @@ -15,7 +15,7 @@ static size_t -sparc_code(lzma_simple *simple lzma_attribute((unused)), +sparc_code(lzma_simple *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size) { diff --git a/contrib/xz/src/lzmainfo/lzmainfo.c b/contrib/xz/src/lzmainfo/lzmainfo.c index 3100dc6..b0ccdfb 100644 --- a/contrib/xz/src/lzmainfo/lzmainfo.c +++ b/contrib/xz/src/lzmainfo/lzmainfo.c @@ -26,7 +26,7 @@ #endif -static void lzma_attribute((noreturn)) +static void lzma_attribute((__noreturn__)) help(void) { printf( @@ -45,7 +45,7 @@ _("Usage: %s [--help] [--version] [FILE]...\n" } -static void lzma_attribute((noreturn)) +static void lzma_attribute((__noreturn__)) version(void) { puts("lzmainfo (" PACKAGE_NAME ") " LZMA_VERSION_STRING); diff --git a/contrib/xz/src/xz/coder.c b/contrib/xz/src/xz/coder.c index 5182ddd..b123ec5 100644 --- a/contrib/xz/src/xz/coder.c +++ b/contrib/xz/src/xz/coder.c @@ -102,7 +102,7 @@ coder_add_filter(lzma_vli id, void *options) } -static void lzma_attribute((noreturn)) +static void lzma_attribute((__noreturn__)) memlimit_too_small(uint64_t memory_usage) { message(V_ERROR, _("Memory usage limit is too low for the given " diff --git a/contrib/xz/src/xz/file_io.c b/contrib/xz/src/xz/file_io.c index 09edcca..f9b7f30 100644 --- a/contrib/xz/src/xz/file_io.c +++ b/contrib/xz/src/xz/file_io.c @@ -53,7 +53,7 @@ static bool io_write_buf(file_pair *pair, const uint8_t *buf, size_t size); extern void io_init(void) { - // Make sure that stdin, stdout, and and stderr are connected to + // Make sure that stdin, stdout, and stderr are connected to // a valid file descriptor. Exit immediately with exit code ERROR // if we cannot make the file descriptors valid. Maybe we should // print an error message, but our stderr could be screwed anyway. diff --git a/contrib/xz/src/xz/hardware.h b/contrib/xz/src/xz/hardware.h index bed952b..ad526f2 100644 --- a/contrib/xz/src/xz/hardware.h +++ b/contrib/xz/src/xz/hardware.h @@ -35,4 +35,4 @@ extern void hardware_memlimit_set(uint64_t new_memlimit, extern uint64_t hardware_memlimit_get(enum operation_mode mode); /// Display the amount of RAM and memory usage limits and exit. -extern void hardware_memlimit_show(void) lzma_attribute((noreturn)); +extern void hardware_memlimit_show(void) lzma_attribute((__noreturn__)); diff --git a/contrib/xz/src/xz/list.c b/contrib/xz/src/xz/list.c index 1c93718..98307eb 100644 --- a/contrib/xz/src/xz/list.c +++ b/contrib/xz/src/xz/list.c @@ -382,14 +382,9 @@ parse_block_header(file_pair *pair, const lzma_index_iter *iter, if (buf.u8[0] == 0) goto data_error; - lzma_block block; - lzma_filter filters[LZMA_FILTERS_MAX + 1]; - - // Initialize the pointers so that they can be passed to free(). - for (size_t i = 0; i < ARRAY_SIZE(filters); ++i) - filters[i].options = NULL; - // Initialize the block structure and decode Block Header Size. + lzma_filter filters[LZMA_FILTERS_MAX + 1]; + lzma_block block; block.version = 0; block.check = iter->stream.flags->check; block.filters = filters; @@ -437,6 +432,10 @@ parse_block_header(file_pair *pair, const lzma_index_iter *iter, break; case LZMA_DATA_ERROR: + // Free the memory allocated by lzma_block_header_decode(). + for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) + free(filters[i].options); + goto data_error; default: @@ -466,14 +465,6 @@ data_error: // Show the error message. message_error("%s: %s", pair->src_name, message_strm(LZMA_DATA_ERROR)); - - // Free the memory allocated by lzma_block_header_decode(). - // This is truly needed only if we get here after a succcessful - // call to lzma_block_header_decode() but it doesn't hurt to - // always do it. - for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) - free(filters[i].options); - return true; } diff --git a/contrib/xz/src/xz/message.c b/contrib/xz/src/xz/message.c index 38cce4a..80c86a4 100644 --- a/contrib/xz/src/xz/message.c +++ b/contrib/xz/src/xz/message.c @@ -94,7 +94,7 @@ static volatile sig_atomic_t progress_needs_updating = false; /// Signal handler for SIGALRM static void -progress_signal_handler(int sig lzma_attribute((unused))) +progress_signal_handler(int sig lzma_attribute((__unused__))) { progress_needs_updating = true; return; @@ -726,7 +726,11 @@ vmessage(enum message_verbosity v, const char *fmt, va_list ap) progress_flush(false); - fprintf(stderr, "%s: ", progname); + // TRANSLATORS: This is the program name in the beginning + // of the line in messages. Usually it becomes "xz: ". + // This is a translatable string because French needs + // a space before a colon. + fprintf(stderr, _("%s: "), progname); vfprintf(stderr, fmt, ap); fputc('\n', stderr); diff --git a/contrib/xz/src/xz/message.h b/contrib/xz/src/xz/message.h index e3fca3c..74599bd 100644 --- a/contrib/xz/src/xz/message.h +++ b/contrib/xz/src/xz/message.h @@ -45,7 +45,7 @@ extern enum message_verbosity message_verbosity_get(void); /// /// This doesn't touch the exit status. extern void message(enum message_verbosity verbosity, const char *fmt, ...) - lzma_attribute((format(printf, 2, 3))); + lzma_attribute((__format__(__printf__, 2, 3))); /// \brief Prints a warning and possibly sets exit status @@ -53,7 +53,7 @@ extern void message(enum message_verbosity verbosity, const char *fmt, ...) /// The message is printed only if verbosity level is at least V_WARNING. /// The exit status is set to WARNING unless it was already at ERROR. extern void message_warning(const char *fmt, ...) - lzma_attribute((format(printf, 1, 2))); + lzma_attribute((__format__(__printf__, 1, 2))); /// \brief Prints an error message and sets exit status @@ -61,25 +61,25 @@ extern void message_warning(const char *fmt, ...) /// The message is printed only if verbosity level is at least V_ERROR. /// The exit status is set to ERROR. extern void message_error(const char *fmt, ...) - lzma_attribute((format(printf, 1, 2))); + lzma_attribute((__format__(__printf__, 1, 2))); /// \brief Prints an error message and exits with EXIT_ERROR /// /// The message is printed only if verbosity level is at least V_ERROR. extern void message_fatal(const char *fmt, ...) - lzma_attribute((format(printf, 1, 2))) - lzma_attribute((noreturn)); + lzma_attribute((__format__(__printf__, 1, 2))) + lzma_attribute((__noreturn__)); /// Print an error message that an internal error occurred and exit with /// EXIT_ERROR. -extern void message_bug(void) lzma_attribute((noreturn)); +extern void message_bug(void) lzma_attribute((__noreturn__)); /// Print a message that establishing signal handlers failed, and exit with /// exit status ERROR. -extern void message_signal_handler(void) lzma_attribute((noreturn)); +extern void message_signal_handler(void) lzma_attribute((__noreturn__)); /// Convert lzma_ret to a string. @@ -116,11 +116,11 @@ extern void message_try_help(void); /// Prints the version number to stdout and exits with exit status SUCCESS. -extern void message_version(void) lzma_attribute((noreturn)); +extern void message_version(void) lzma_attribute((__noreturn__)); /// Print the help message. -extern void message_help(bool long_help) lzma_attribute((noreturn)); +extern void message_help(bool long_help) lzma_attribute((__noreturn__)); /// \brief Set the total number of files to be processed diff --git a/contrib/xz/src/xz/options.c b/contrib/xz/src/xz/options.c index 379a2e4..f21a0ba 100644 --- a/contrib/xz/src/xz/options.c +++ b/contrib/xz/src/xz/options.c @@ -150,7 +150,7 @@ enum { static void set_delta(void *options, uint32_t key, uint64_t value, - const char *valuestr lzma_attribute((unused))) + const char *valuestr lzma_attribute((__unused__))) { lzma_options_delta *opt = options; switch (key) { @@ -194,7 +194,7 @@ enum { static void set_bcj(void *options, uint32_t key, uint64_t value, - const char *valuestr lzma_attribute((unused))) + const char *valuestr lzma_attribute((__unused__))) { lzma_options_bcj *opt = options; switch (key) { @@ -241,7 +241,7 @@ enum { }; -static void lzma_attribute((noreturn)) +static void lzma_attribute((__noreturn__)) error_lzma_preset(const char *valuestr) { message_fatal(_("Unsupported LZMA1/LZMA2 preset: %s"), valuestr); diff --git a/contrib/xz/src/xz/signals.c b/contrib/xz/src/xz/signals.c index 4d6a9da..de21364 100644 --- a/contrib/xz/src/xz/signals.c +++ b/contrib/xz/src/xz/signals.c @@ -179,7 +179,7 @@ signals_exit(void) // console window. static BOOL WINAPI -signal_handler(DWORD type lzma_attribute((unused))) +signal_handler(DWORD type lzma_attribute((__unused__))) { // Since we don't get a signal number which we could raise() at // signals_exit() like on POSIX, just set the exit status to diff --git a/contrib/xz/src/xz/suffix.c b/contrib/xz/src/xz/suffix.c index ea86c1a..c89f67f 100644 --- a/contrib/xz/src/xz/suffix.c +++ b/contrib/xz/src/xz/suffix.c @@ -21,12 +21,6 @@ static char *custom_suffix = NULL; -struct suffix_pair { - const char *compressed; - const char *uncompressed; -}; - - /// \brief Test if the char is a directory separator static bool is_dir_sep(char c) @@ -86,7 +80,10 @@ test_suffix(const char *suffix, const char *src_name, size_t src_len) static char * uncompressed_name(const char *src_name, const size_t src_len) { - static const struct suffix_pair suffixes[] = { + static const struct { + const char *compressed; + const char *uncompressed; + } suffixes[] = { { ".xz", "" }, { ".txz", ".tar" }, // .txz abbreviation for .txt.gz is rare. { ".lzma", "" }, @@ -145,25 +142,25 @@ static char * compressed_name(const char *src_name, const size_t src_len) { // The order of these must match the order in args.h. - static const struct suffix_pair all_suffixes[][3] = { + static const char *const all_suffixes[][3] = { { - { ".xz", "" }, - { ".txz", ".tar" }, - { NULL, NULL } + ".xz", + ".txz", + NULL }, { - { ".lzma", "" }, - { ".tlz", ".tar" }, - { NULL, NULL } + ".lzma", + ".tlz", + NULL /* }, { - { ".gz", "" }, - { ".tgz", ".tar" }, - { NULL, NULL } + ".gz", + ".tgz", + NULL */ }, { // --format=raw requires specifying the suffix // manually or using stdout. - { NULL, NULL } + NULL } }; @@ -171,14 +168,22 @@ compressed_name(const char *src_name, const size_t src_len) assert(opt_format != FORMAT_AUTO); const size_t format = opt_format - 1; - const struct suffix_pair *const suffixes = all_suffixes[format]; + const char *const *suffixes = all_suffixes[format]; + + for (size_t i = 0; suffixes[i] != NULL; ++i) { + if (test_suffix(suffixes[i], src_name, src_len) != 0) { + message_warning(_("%s: File already has `%s' " + "suffix, skipping"), src_name, + suffixes[i]); + return NULL; + } + } - for (size_t i = 0; suffixes[i].compressed != NULL; ++i) { - if (test_suffix(suffixes[i].compressed, src_name, src_len) - != 0) { + if (custom_suffix != NULL) { + if (test_suffix(custom_suffix, src_name, src_len) != 0) { message_warning(_("%s: File already has `%s' " "suffix, skipping"), src_name, - suffixes[i].compressed); + custom_suffix); return NULL; } } @@ -193,7 +198,7 @@ compressed_name(const char *src_name, const size_t src_len) } const char *suffix = custom_suffix != NULL - ? custom_suffix : suffixes[0].compressed; + ? custom_suffix : suffixes[0]; const size_t suffix_len = strlen(suffix); char *dest_name = xmalloc(src_len + suffix_len + 1); diff --git a/contrib/xz/src/xz/util.h b/contrib/xz/src/xz/util.h index 4b2d3e2..a2516bf 100644 --- a/contrib/xz/src/xz/util.h +++ b/contrib/xz/src/xz/util.h @@ -20,11 +20,11 @@ /// \brief Safe realloc() that never returns NULL extern void *xrealloc(void *ptr, size_t size) - lzma_attribute((malloc)) lzma_attr_alloc_size(2); + lzma_attribute((__malloc__)) lzma_attr_alloc_size(2); /// \brief Safe strdup() that never returns NULL -extern char *xstrdup(const char *src) lzma_attribute((malloc)); +extern char *xstrdup(const char *src) lzma_attribute((__malloc__)); /// \brief Fancy version of strtoull() @@ -102,7 +102,7 @@ extern const char *uint64_to_nicestr(uint64_t value, /// A maximum of *left bytes is written starting from *pos. *pos and *left /// are updated accordingly. extern void my_snprintf(char **pos, size_t *left, const char *fmt, ...) - lzma_attribute((format(printf, 3, 4))); + lzma_attribute((__format__(__printf__, 3, 4))); /// \brief Check if filename is empty and print an error message diff --git a/contrib/xz/src/xz/xz.1 b/contrib/xz/src/xz/xz.1 index cba1d07..f1c9135 100644 --- a/contrib/xz/src/xz/xz.1 +++ b/contrib/xz/src/xz/xz.1 @@ -866,7 +866,7 @@ This is equivalent to specifying \fB\-\-memlimit\-compress=\fIlimit \fB\-\-memlimit\-decompress=\fIlimit\fR. .TP .B \-\-no\-adjust -Display an error and exit if the compression settings exceed the +Display an error and exit if the compression settings exceed the memory usage limit. The default is to adjust the settings downwards so that the memory usage limit is not exceeded. diff --git a/contrib/xz/src/xzdec/xzdec.c b/contrib/xz/src/xzdec/xzdec.c index fd01507..b7830db 100644 --- a/contrib/xz/src/xzdec/xzdec.c +++ b/contrib/xz/src/xzdec/xzdec.c @@ -40,7 +40,7 @@ static unsigned int display_errors = 2; -static void lzma_attribute((format(printf, 1, 2))) +static void lzma_attribute((__format__(__printf__, 1, 2))) my_errorf(const char *fmt, ...) { va_list ap; @@ -57,7 +57,7 @@ my_errorf(const char *fmt, ...) } -static void lzma_attribute((noreturn)) +static void lzma_attribute((__noreturn__)) help(void) { printf( @@ -81,7 +81,7 @@ PACKAGE_NAME " home page: <" PACKAGE_URL ">\n", progname); } -static void lzma_attribute((noreturn)) +static void lzma_attribute((__noreturn__)) version(void) { printf(TOOL_FORMAT "dec (" PACKAGE_NAME ") " LZMA_VERSION_STRING "\n" |