]> git.ipfire.org Git - thirdparty/git.git/commitdiff
advice.h: add missing __attribute__((format)) & fix usage
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 13 Jul 2021 08:05:20 +0000 (10:05 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Jul 2021 22:20:20 +0000 (15:20 -0700)
Add the missing __attribute__((format)) checking to
advise_if_enabled(). This revealed a trivial issue introduced in
b3b18d16213 (advice: revamp advise API, 2020-03-02). We treated the
argv[1] as a format string, but did not intend to do so. Let's use
"%s" and pass argv[1] as an argument instead.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
advice.h
t/helper/test-advise.c

index bd26c385d00dd3af9e9bbd60812697607107b8dd..9f8ffc73546b3939ad5ca9496b187c7aeb60242e 100644 (file)
--- a/advice.h
+++ b/advice.h
@@ -90,6 +90,7 @@ int advice_enabled(enum advice_type type);
 /**
  * Checks the visibility of the advice before printing.
  */
+__attribute__((format (printf, 2, 3)))
 void advise_if_enabled(enum advice_type type, const char *advice, ...);
 
 int error_resolve_conflict(const char *me);
index a7043df1d38ad3e94c76390dc5c33157c72fc76d..cb881139f7316f475ea072c1b549aafe7cca2ad1 100644 (file)
@@ -16,7 +16,7 @@ int cmd__advise_if_enabled(int argc, const char **argv)
         * selected here and in t0018 where this command is being
         * executed.
         */
-       advise_if_enabled(ADVICE_NESTED_TAG, argv[1]);
+       advise_if_enabled(ADVICE_NESTED_TAG, "%s", argv[1]);
 
        return 0;
 }