From 6993486ed8f14992cc228021b7e96a7a576e827c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 1 Nov 2024 23:18:30 -0700 Subject: [PATCH] Avoid unlikely verbose_option overflow * src/tar.c (parse_opt, decode_options): Avoid undefined behavior if verbose_option overflows. --- src/tar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tar.c b/src/tar.c index 3a4421e9..66486fcf 100644 --- a/src/tar.c +++ b/src/tar.c @@ -1797,7 +1797,7 @@ parse_opt (int key, char *arg, struct argp_state *state) case 't': set_subcommand_option (LIST_SUBCOMMAND); - verbose_option++; + verbose_option += verbose_option <= 2; break; case TEST_LABEL_OPTION: @@ -1825,7 +1825,7 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case 'v': - verbose_option++; + verbose_option += verbose_option <= 2; warning_option |= WARN_VERBOSE_WARNINGS; break; @@ -2710,7 +2710,7 @@ decode_options (int argc, char **argv) /* --test-label is silent if the user has specified the label name to compare against. */ if (!name_more_files ()) - verbose_option++; + verbose_option += verbose_option <= 2; } else if (utc_option) verbose_option = 2;