Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 4621085

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent edca415 commit 4621085

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern int advice_detached_head;
1919
extern int advice_set_upstream_failure;
2020

2121
int git_default_advice_config(const char *var, const char *value);
22+
__attribute__((format (printf, 1, 2)))
2223
void advise(const char *advice, ...);
2324
int error_resolve_conflict(const char *me);
2425
extern void NORETURN die_resolve_conflict(const char *me);

trace.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static void trace_vprintf(const char *key, const char *fmt, va_list ap)
7575
strbuf_release(&buf);
7676
}
7777

78+
__attribute__((format (printf, 2, 3)))
7879
static void trace_printf_key(const char *key, const char *fmt, ...)
7980
{
8081
va_list ap;

transport-helper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ int transport_helper_init(struct transport *transport, const char *name)
955955
#define PBUFFERSIZE 8192
956956

957957
/* Print bidirectional transfer loop debug message. */
958+
__attribute__((format (printf, 1, 2)))
958959
static void transfer_debug(const char *fmt, ...)
959960
{
960961
va_list args;
@@ -1040,7 +1041,7 @@ static int udt_do_read(struct unidirectional_transfer *t)
10401041
return -1;
10411042
} else if (bytes == 0) {
10421043
transfer_debug("%s EOF (with %i bytes in buffer)",
1043-
t->src_name, t->bufuse);
1044+
t->src_name, (int)t->bufuse);
10441045
t->state = SSTATE_FLUSHING;
10451046
} else if (bytes > 0) {
10461047
t->bufuse += bytes;

utf8.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ int utf8_strwidth(const char *string);
1010
int is_utf8(const char *text);
1111
int is_encoding_utf8(const char *name);
1212
int same_encoding(const char *, const char *);
13+
__attribute__((format (printf, 2, 3)))
1314
int utf8_fprintf(FILE *, const char *, ...);
1415

1516
void strbuf_add_wrapped_text(struct strbuf *buf,

0 commit comments

Comments
 (0)