advice.h: add missing __attribute__((format)) & fix usage
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>
Ævar Arnfjörð Bjarmason committed
Jul 13, 2021 at 10:05 UTC
927dc33070563d6646c903daf919dde80d8878d4
2 files changed
+2
-1
advice.h
+1
@@ -90,6 +90,7 @@ int advice_enabled(enum advice_type type);
90
/**
91
* Checks the visibility of the advice before printing.
92
*/
93
+__attribute__((format (printf, 2, 3)))
94
void advise_if_enabled(enum advice_type type, const char *advice, ...);
95
96
int error_resolve_conflict(const char *me);
t/helper/test-advise.c
+1
-1
@@ -16,7 +16,7 @@ int cmd__advise_if_enabled(int argc, const char **argv)
16
* selected here and in t0018 where this command is being
17
* executed.
18
*/
19
- advise_if_enabled(ADVICE_NESTED_TAG, argv[1]);
19
+ advise_if_enabled(ADVICE_NESTED_TAG, "%s", argv[1]);
20
21
return 0;
22
}