diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2021-02-28 23:21:27 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2021-03-01 00:18:44 -0800 |
commit | daf634c44e2714c7525e6c552c5a5adc87cba887 (patch) | |
tree | 7a990326144c81fb9e774f8081dd643b29be9b99 | |
parent | 5f8f129415089455b687cc94d88a667eb51f6647 (diff) | |
download | tar-daf634c44e2714c7525e6c552c5a5adc87cba887.tar.gz |
Pacify --enable-gcc-warnings -flto -fanalyzer
With GCC 10.2.1, ‘./configure --enable-gcc-warnings CFLAGS='-O2
-flto -fanalyzer' issued a false alarm about uninitialized
variable use. Pacify GCC by using a variant of the code.
* src/buffer.c (zip_program): Omit last placeholder entry.
(n_zip_programs): New constant.
(find_zip_program): Use it instead of placeholder.
(first_decompress_program): Set *PSTATE to maximum value
if skipping the table. This avoids confusing gcc -flto
into thinking *PSTATE is used uninitialized.
(next_decompress_program): Simplify now that *PSTATE is maximal
when skipping.
-rw-r--r-- | src/buffer.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/buffer.c b/src/buffer.c index a5e74de7..433cb594 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -328,15 +328,15 @@ static struct zip_program zip_program[] = { { ct_lzop, LZOP_PROGRAM, "--lzop" }, { ct_xz, XZ_PROGRAM, "-J" }, { ct_zstd, ZSTD_PROGRAM, "--zstd" }, - { ct_none } }; +enum { n_zip_programs = sizeof zip_program / sizeof *zip_program }; static struct zip_program const * find_zip_program (enum compress_type type, int *pstate) { int i; - for (i = *pstate; zip_program[i].type != ct_none; i++) + for (i = *pstate; i < n_zip_programs; i++) { if (zip_program[i].type == type) { @@ -353,6 +353,8 @@ first_decompress_program (int *pstate) { struct zip_program const *zp; + *pstate = n_zip_programs; + if (use_compress_program_option) return use_compress_program_option; @@ -369,8 +371,6 @@ next_decompress_program (int *pstate) { struct zip_program const *zp; - if (use_compress_program_option) - return NULL; zp = find_zip_program (archive_compression_type, pstate); return zp ? zp->program : NULL; } |