Skip to content

Commit 28bea9e

Browse files
Tarmigan Caseboltgitster
authored andcommitted
Check the format of more printf-type functions
We already have these checks in many printf-type functions that have prototypes which are in header files. Add these same checks to some more prototypes in header functions and to static functions in .c files. cc: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Tarmigan Casebolt <tarmigan+git@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 77097fa commit 28bea9e

File tree

10 files changed

+22
-3
lines changed

10 files changed

+22
-3
lines changed

builtin-fsck.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static void objreport(struct object *obj, const char *severity,
4747
fputs("\n", stderr);
4848
}
4949

50+
__attribute__((format (printf, 2, 3)))
5051
static int objerror(struct object *obj, const char *err, ...)
5152
{
5253
va_list params;
@@ -57,6 +58,7 @@ static int objerror(struct object *obj, const char *err, ...)
5758
return -1;
5859
}
5960

61+
__attribute__((format (printf, 3, 4)))
6062
static int fsck_error_func(struct object *obj, int type, const char *err, ...)
6163
{
6264
va_list params;

builtin-update-index.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static int mark_valid_only;
2727
#define MARK_VALID 1
2828
#define UNMARK_VALID 2
2929

30+
__attribute__((format (printf, 1, 2)))
3031
static void report(const char *fmt, ...)
3132
{
3233
va_list vp;

builtin-upload-archive.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ static int run_upload_archive(int argc, const char **argv, const char *prefix)
6767
return write_archive(sent_argc, sent_argv, prefix, 0);
6868
}
6969

70+
__attribute__((format (printf, 1, 2)))
7071
static void error_clnt(const char *fmt, ...)
7172
{
7273
char buf[1024];

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,9 @@ extern void *alloc_object_node(void);
961961
extern void alloc_report(void);
962962

963963
/* trace.c */
964+
__attribute__((format (printf, 1, 2)))
964965
extern void trace_printf(const char *format, ...);
966+
__attribute__((format (printf, 2, 3)))
965967
extern void trace_argv_printf(const char **argv, const char *format, ...);
966968

967969
/* convert.c */

color.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ int git_color_default_config(const char *var, const char *value, void *cb);
2929
int git_config_colorbool(const char *var, const char *value, int stdout_is_tty);
3030
void color_parse(const char *value, const char *var, char *dst);
3131
void color_parse_mem(const char *value, int len, const char *var, char *dst);
32+
__attribute__((format (printf, 3, 4)))
3233
int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
34+
__attribute__((format (printf, 3, 4)))
3335
int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
3436
int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf);
3537

daemon.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static void logreport(int priority, const char *err, va_list params)
7777
}
7878
}
7979

80+
__attribute__((format (printf, 1, 2)))
8081
static void logerror(const char *err, ...)
8182
{
8283
va_list params;
@@ -85,6 +86,7 @@ static void logerror(const char *err, ...)
8586
va_end(params);
8687
}
8788

89+
__attribute__((format (printf, 1, 2)))
8890
static void loginfo(const char *err, ...)
8991
{
9092
va_list params;

fsck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ typedef int (*fsck_walk_func)(struct object *obj, int type, void *data);
1717
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
1818
typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...);
1919

20+
__attribute__((format (printf, 3, 4)))
2021
int fsck_error_function(struct object *obj, int type, const char *fmt, ...);
2122

2223
/* descend in all linked child objects

imap-send.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,16 @@ struct msg_data {
100100

101101
static int Verbose, Quiet;
102102

103+
__attribute__((format (printf, 1, 2)))
103104
static void imap_info(const char *, ...);
105+
__attribute__((format (printf, 1, 2)))
104106
static void imap_warn(const char *, ...);
105107

106108
static char *next_arg(char **);
107109

108110
static void free_generic_messages(struct message *);
109111

112+
__attribute__((format (printf, 3, 4)))
110113
static int nfsnprintf(char *buf, int blen, const char *fmt, ...);
111114

112115
static int nfvasprintf(char **strp, const char *fmt, va_list ap)
@@ -600,6 +603,7 @@ static struct imap_cmd *v_issue_imap_cmd(struct imap_store *ctx,
600603
return cmd;
601604
}
602605

606+
__attribute__((format (printf, 3, 4)))
603607
static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
604608
struct imap_cmd_cb *cb,
605609
const char *fmt, ...)
@@ -613,6 +617,7 @@ static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
613617
return ret;
614618
}
615619

620+
__attribute__((format (printf, 3, 4)))
616621
static int imap_exec(struct imap_store *ctx, struct imap_cmd_cb *cb,
617622
const char *fmt, ...)
618623
{
@@ -628,6 +633,7 @@ static int imap_exec(struct imap_store *ctx, struct imap_cmd_cb *cb,
628633
return get_cmd_result(ctx, cmdp);
629634
}
630635

636+
__attribute__((format (printf, 3, 4)))
631637
static int imap_exec_m(struct imap_store *ctx, struct imap_cmd_cb *cb,
632638
const char *fmt, ...)
633639
{
@@ -918,7 +924,7 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
918924
if (!strcmp("NO", arg)) {
919925
if (cmdp->cb.create && cmd && (cmdp->cb.trycreate || !memcmp(cmd, "[TRYCREATE]", 11))) { /* SELECT, APPEND or UID COPY */
920926
p = strchr(cmdp->cmd, '"');
921-
if (!issue_imap_cmd(ctx, NULL, "CREATE \"%.*s\"", strchr(p + 1, '"') - p + 1, p)) {
927+
if (!issue_imap_cmd(ctx, NULL, "CREATE \"%.*s\"", (int)(strchr(p + 1, '"') - p + 1), p)) {
922928
resp = RESP_BAD;
923929
goto normal;
924930
}

merge-recursive.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static void flush_output(struct merge_options *o)
8686
}
8787
}
8888

89+
__attribute__((format (printf, 3, 4)))
8990
static void output(struct merge_options *o, int v, const char *fmt, ...)
9091
{
9192
int len;
@@ -214,7 +215,8 @@ struct tree *write_tree_from_memory(struct merge_options *o)
214215
for (i = 0; i < active_nr; i++) {
215216
struct cache_entry *ce = active_cache[i];
216217
if (ce_stage(ce))
217-
output(o, 0, "%d %.*s", ce_stage(ce), ce_namelen(ce), ce->name);
218+
output(o, 0, "%d %.*s", ce_stage(ce),
219+
(int)ce_namelen(ce), ce->name);
218220
}
219221
return NULL;
220222
}

strbuf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct strbuf_expand_dict_entry {
117117
};
118118
extern size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder, void *context);
119119

120-
__attribute__((format(printf,2,3)))
120+
__attribute__((format (printf,2,3)))
121121
extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
122122

123123
extern size_t strbuf_fread(struct strbuf *, size_t, FILE *);

0 commit comments

Comments
 (0)