Skip to content

Commit dd6d3c9

Browse files
committed
Merge branch 'ab/attribute-format'
Many "printf"-like helper functions we have have been annotated with __attribute__() to catch placeholder/parameter mismatches. * ab/attribute-format: advice.h: add missing __attribute__((format)) & fix usage *.h: add a few missing __attribute__((format)) *.c static functions: add missing __attribute__((format)) sequencer.c: move static function to avoid forward decl *.c static functions: don't forward-declare __attribute__
2 parents c9d6d8a + 927dc33 commit dd6d3c9

23 files changed

+47
-29
lines changed

add-patch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ static void add_p_state_clear(struct add_p_state *s)
280280
clear_add_i_state(&s->s);
281281
}
282282

283+
__attribute__((format (printf, 2, 3)))
283284
static void err(struct add_p_state *s, const char *fmt, ...)
284285
{
285286
va_list args;

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ int advice_enabled(enum advice_type type);
9090
/**
9191
* Checks the visibility of the advice before printing.
9292
*/
93+
__attribute__((format (printf, 2, 3)))
9394
void advise_if_enabled(enum advice_type type, const char *advice, ...);
9495

9596
int error_resolve_conflict(const char *me);

builtin/am.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ static void write_state_bool(const struct am_state *state,
210210
* If state->quiet is false, calls fprintf(fp, fmt, ...), and appends a newline
211211
* at the end.
212212
*/
213+
__attribute__((format (printf, 3, 4)))
213214
static void say(const struct am_state *state, FILE *fp, const char *fmt, ...)
214215
{
215216
va_list ap;

builtin/bisect--helper.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ static int write_in_file(const char *path, const char *mode, const char *format,
117117
return fclose(fp);
118118
}
119119

120+
__attribute__((format (printf, 2, 3)))
120121
static int write_to_file(const char *path, const char *format, ...)
121122
{
122123
int res;
@@ -129,6 +130,7 @@ static int write_to_file(const char *path, const char *format, ...)
129130
return res;
130131
}
131132

133+
__attribute__((format (printf, 2, 3)))
132134
static int append_to_file(const char *path, const char *format, ...)
133135
{
134136
int res;

builtin/index-pack.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,7 @@ static void parse_pack_header(void)
369369
use(sizeof(struct pack_header));
370370
}
371371

372-
static NORETURN void bad_object(off_t offset, const char *format,
373-
...) __attribute__((format (printf, 2, 3)));
374-
372+
__attribute__((format (printf, 2, 3)))
375373
static NORETURN void bad_object(off_t offset, const char *format, ...)
376374
{
377375
va_list params;

builtin/receive-pack.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,6 @@ static int proc_receive_ref_matches(struct command *cmd)
425425
return 0;
426426
}
427427

428-
static void rp_error(const char *err, ...) __attribute__((format (printf, 1, 2)));
429-
static void rp_warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
430-
431428
static void report_message(const char *prefix, const char *err, va_list params)
432429
{
433430
int sz;
@@ -445,6 +442,7 @@ static void report_message(const char *prefix, const char *err, va_list params)
445442
xwrite(2, msg, sz);
446443
}
447444

445+
__attribute__((format (printf, 1, 2)))
448446
static void rp_warning(const char *err, ...)
449447
{
450448
va_list params;
@@ -453,6 +451,7 @@ static void rp_warning(const char *err, ...)
453451
va_end(params);
454452
}
455453

454+
__attribute__((format (printf, 1, 2)))
456455
static void rp_error(const char *err, ...)
457456
{
458457
va_list params;

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,7 @@ enum get_oid_result {
13851385
};
13861386

13871387
int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
1388+
__attribute__((format (printf, 2, 3)))
13881389
int get_oidf(struct object_id *oid, const char *fmt, ...);
13891390
int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid);
13901391
int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid);

commit-graph.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,6 +2408,7 @@ int write_commit_graph(struct object_directory *odb,
24082408
#define VERIFY_COMMIT_GRAPH_ERROR_HASH 2
24092409
static int verify_commit_graph_error;
24102410

2411+
__attribute__((format (printf, 1, 2)))
24112412
static void graph_report(const char *fmt, ...)
24122413
{
24132414
va_list ap;

contrib/credential/osxkeychain/git-credential-osxkeychain.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ static char *username;
1010
static char *password;
1111
static UInt16 port;
1212

13+
__attribute__((format (printf, 1, 2)))
1314
static void die(const char *err, ...)
1415
{
1516
char msg[4096];

contrib/credential/wincred/git-credential-wincred.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
1313

14+
__attribute__((format (printf, 1, 2)))
1415
static void die(const char *err, ...)
1516
{
1617
char msg[4096];

0 commit comments

Comments
 (0)