add missing "format" function attributes
For most of our functions that take printf-like formats, we use gcc's __attribute__((format)) to get compiler warnings when the functions are misused. Let's give a few more functions the same protection. In most cases, the annotations do not uncover any actual bugs; the only code change needed is that we passed a size_t to transfer_debug, which expected an int. Since we expect the passed-in value to be a relatively small buffer size (and cast a similar value to int directly below), we can just cast away the problem. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jul 9, 2013 at 20:18 UTC
4621085b7eb2f4cffe16d508988ff9b4a874b4ef
4 files changed
+5
-1
advice.h
+1
@@ -19,6 +19,7 @@ extern int advice_detached_head;
19
extern int advice_set_upstream_failure;
20
21
int git_default_advice_config(const char *var, const char *value);
22
+__attribute__((format (printf, 1, 2)))
23
void advise(const char *advice, ...);
24
int error_resolve_conflict(const char *me);
25
extern void NORETURN die_resolve_conflict(const char *me);
trace.c
+1
@@ -75,6 +75,7 @@ static void trace_vprintf(const char *key, const char *fmt, va_list ap)
75
strbuf_release(&buf);
76
}
77
78
+__attribute__((format (printf, 2, 3)))
79
static void trace_printf_key(const char *key, const char *fmt, ...)
80
{
81
va_list ap;
transport-helper.c
+2
-1
@@ -955,6 +955,7 @@ int transport_helper_init(struct transport *transport, const char *name)
955
#define PBUFFERSIZE 8192
956
957
/* Print bidirectional transfer loop debug message. */
958
+__attribute__((format (printf, 1, 2)))
959
static void transfer_debug(const char *fmt, ...)
960
{
961
va_list args;
@@ -1040,7 +1041,7 @@ static int udt_do_read(struct unidirectional_transfer *t)
1041
return -1;
1042
} else if (bytes == 0) {
1043
transfer_debug("%s EOF (with %i bytes in buffer)",
1043
- t->src_name, t->bufuse);
1044
+ t->src_name, (int)t->bufuse);
1045
t->state = SSTATE_FLUSHING;
1046
} else if (bytes > 0) {
1047
t->bufuse += bytes;
utf8.h
+1
@@ -10,6 +10,7 @@ int utf8_strwidth(const char *string);
10
int is_utf8(const char *text);
11
int is_encoding_utf8(const char *name);
12
int same_encoding(const char *, const char *);
13
+__attribute__((format (printf, 2, 3)))
14
int utf8_fprintf(FILE *, const char *, ...);
15
16
void strbuf_add_wrapped_text(struct strbuf *buf,