Skip to content

Commit

Permalink
add missing "format" function attributes
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
peff authored and gitster committed Jul 10, 2013
1 parent edca415 commit 4621085
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions advice.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern int advice_detached_head;
extern int advice_set_upstream_failure;

int git_default_advice_config(const char *var, const char *value);
__attribute__((format (printf, 1, 2)))
void advise(const char *advice, ...);
int error_resolve_conflict(const char *me);
extern void NORETURN die_resolve_conflict(const char *me);
Expand Down
1 change: 1 addition & 0 deletions trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static void trace_vprintf(const char *key, const char *fmt, va_list ap)
strbuf_release(&buf);
}

__attribute__((format (printf, 2, 3)))
static void trace_printf_key(const char *key, const char *fmt, ...)
{
va_list ap;
Expand Down
3 changes: 2 additions & 1 deletion transport-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@ int transport_helper_init(struct transport *transport, const char *name)
#define PBUFFERSIZE 8192

/* Print bidirectional transfer loop debug message. */
__attribute__((format (printf, 1, 2)))
static void transfer_debug(const char *fmt, ...)
{
va_list args;
Expand Down Expand Up @@ -1040,7 +1041,7 @@ static int udt_do_read(struct unidirectional_transfer *t)
return -1;
} else if (bytes == 0) {
transfer_debug("%s EOF (with %i bytes in buffer)",
t->src_name, t->bufuse);
t->src_name, (int)t->bufuse);
t->state = SSTATE_FLUSHING;
} else if (bytes > 0) {
t->bufuse += bytes;
Expand Down
1 change: 1 addition & 0 deletions utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ int utf8_strwidth(const char *string);
int is_utf8(const char *text);
int is_encoding_utf8(const char *name);
int same_encoding(const char *, const char *);
__attribute__((format (printf, 2, 3)))
int utf8_fprintf(FILE *, const char *, ...);

void strbuf_add_wrapped_text(struct strbuf *buf,
Expand Down

0 comments on commit 4621085

Please sign in to comment.