Merge branch 'jk/gcc-function-attributes'
Use the function attributes extension to catch mistakes in use of our own variadic functions that use NULL sentinel at the end (i.e. like execl(3)) and format strings (i.e. like printf(3)). * jk/gcc-function-attributes: Add the LAST_ARG_MUST_BE_NULL macro wt-status: use "format" function attribute for status_printf use "sentinel" function attribute for variadic lists add missing "format" function attributes
This commit is contained in:
commit
e9f1a6c189
1
advice.h
1
advice.h
@ -21,6 +21,7 @@ extern int advice_object_name_warning;
|
|||||||
extern int advice_rm_hints;
|
extern int advice_rm_hints;
|
||||||
|
|
||||||
int git_default_advice_config(const char *var, const char *value);
|
int git_default_advice_config(const char *var, const char *value);
|
||||||
|
__attribute__((format (printf, 1, 2)))
|
||||||
void advise(const char *advice, ...);
|
void advise(const char *advice, ...);
|
||||||
int error_resolve_conflict(const char *me);
|
int error_resolve_conflict(const char *me);
|
||||||
extern void NORETURN die_resolve_conflict(const char *me);
|
extern void NORETURN die_resolve_conflict(const char *me);
|
||||||
|
@ -15,6 +15,7 @@ void argv_array_init(struct argv_array *);
|
|||||||
void argv_array_push(struct argv_array *, const char *);
|
void argv_array_push(struct argv_array *, const char *);
|
||||||
__attribute__((format (printf,2,3)))
|
__attribute__((format (printf,2,3)))
|
||||||
void argv_array_pushf(struct argv_array *, const char *fmt, ...);
|
void argv_array_pushf(struct argv_array *, const char *fmt, ...);
|
||||||
|
LAST_ARG_MUST_BE_NULL
|
||||||
void argv_array_pushl(struct argv_array *, ...);
|
void argv_array_pushl(struct argv_array *, ...);
|
||||||
void argv_array_pop(struct argv_array *);
|
void argv_array_pop(struct argv_array *);
|
||||||
void argv_array_clear(struct argv_array *);
|
void argv_array_clear(struct argv_array *);
|
||||||
|
@ -54,6 +54,7 @@ static int option_parse_x(const struct option *opt,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LAST_ARG_MUST_BE_NULL
|
||||||
static void verify_opt_compatible(const char *me, const char *base_opt, ...)
|
static void verify_opt_compatible(const char *me, const char *base_opt, ...)
|
||||||
{
|
{
|
||||||
const char *this_opt;
|
const char *this_opt;
|
||||||
@ -70,6 +71,7 @@ static void verify_opt_compatible(const char *me, const char *base_opt, ...)
|
|||||||
die(_("%s: %s cannot be used with %s"), me, this_opt, base_opt);
|
die(_("%s: %s cannot be used with %s"), me, this_opt, base_opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LAST_ARG_MUST_BE_NULL
|
||||||
static void verify_opt_mutually_compatible(const char *me, ...)
|
static void verify_opt_mutually_compatible(const char *me, ...)
|
||||||
{
|
{
|
||||||
const char *opt1, *opt2 = NULL;
|
const char *opt1, *opt2 = NULL;
|
||||||
|
@ -7,6 +7,7 @@ extern const char *git_exec_path(void);
|
|||||||
extern void setup_path(void);
|
extern void setup_path(void);
|
||||||
extern const char **prepare_git_cmd(const char **argv);
|
extern const char **prepare_git_cmd(const char **argv);
|
||||||
extern int execv_git_cmd(const char **argv); /* NULL terminated */
|
extern int execv_git_cmd(const char **argv); /* NULL terminated */
|
||||||
|
LAST_ARG_MUST_BE_NULL
|
||||||
extern int execl_git_cmd(const char *cmd, ...);
|
extern int execl_git_cmd(const char *cmd, ...);
|
||||||
extern const char *system_path(const char *path);
|
extern const char *system_path(const char *path);
|
||||||
|
|
||||||
|
@ -303,6 +303,13 @@ extern char *gitbasename(char *);
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* The sentinel attribute is valid from gcc version 4.0 */
|
||||||
|
#if defined(__GNUC__) && (__GNUC__ >= 4)
|
||||||
|
#define LAST_ARG_MUST_BE_NULL __attribute__((sentinel))
|
||||||
|
#else
|
||||||
|
#define LAST_ARG_MUST_BE_NULL
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "compat/bswap.h"
|
#include "compat/bswap.h"
|
||||||
|
|
||||||
#ifdef USE_WILDMATCH
|
#ifdef USE_WILDMATCH
|
||||||
|
@ -46,6 +46,7 @@ int finish_command(struct child_process *);
|
|||||||
int run_command(struct child_process *);
|
int run_command(struct child_process *);
|
||||||
|
|
||||||
extern char *find_hook(const char *name);
|
extern char *find_hook(const char *name);
|
||||||
|
LAST_ARG_MUST_BE_NULL
|
||||||
extern int run_hook(const char *index_file, const char *name, ...);
|
extern int run_hook(const char *index_file, const char *name, ...);
|
||||||
|
|
||||||
#define RUN_COMMAND_NO_STDIN 1
|
#define RUN_COMMAND_NO_STDIN 1
|
||||||
|
1
trace.c
1
trace.c
@ -75,6 +75,7 @@ static void trace_vprintf(const char *key, const char *fmt, va_list ap)
|
|||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((format (printf, 2, 3)))
|
||||||
static void trace_printf_key(const char *key, const char *fmt, ...)
|
static void trace_printf_key(const char *key, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
@ -982,6 +982,7 @@ int transport_helper_init(struct transport *transport, const char *name)
|
|||||||
#define PBUFFERSIZE 8192
|
#define PBUFFERSIZE 8192
|
||||||
|
|
||||||
/* Print bidirectional transfer loop debug message. */
|
/* Print bidirectional transfer loop debug message. */
|
||||||
|
__attribute__((format (printf, 1, 2)))
|
||||||
static void transfer_debug(const char *fmt, ...)
|
static void transfer_debug(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -1067,7 +1068,7 @@ static int udt_do_read(struct unidirectional_transfer *t)
|
|||||||
return -1;
|
return -1;
|
||||||
} else if (bytes == 0) {
|
} else if (bytes == 0) {
|
||||||
transfer_debug("%s EOF (with %i bytes in buffer)",
|
transfer_debug("%s EOF (with %i bytes in buffer)",
|
||||||
t->src_name, t->bufuse);
|
t->src_name, (int)t->bufuse);
|
||||||
t->state = SSTATE_FLUSHING;
|
t->state = SSTATE_FLUSHING;
|
||||||
} else if (bytes > 0) {
|
} else if (bytes > 0) {
|
||||||
t->bufuse += bytes;
|
t->bufuse += bytes;
|
||||||
|
1
utf8.h
1
utf8.h
@ -10,6 +10,7 @@ int utf8_strwidth(const char *string);
|
|||||||
int is_utf8(const char *text);
|
int is_utf8(const char *text);
|
||||||
int is_encoding_utf8(const char *name);
|
int is_encoding_utf8(const char *name);
|
||||||
int same_encoding(const char *, const char *);
|
int same_encoding(const char *, const char *);
|
||||||
|
__attribute__((format (printf, 2, 3)))
|
||||||
int utf8_fprintf(FILE *, const char *, ...);
|
int utf8_fprintf(FILE *, const char *, ...);
|
||||||
|
|
||||||
void strbuf_add_wrapped_text(struct strbuf *buf,
|
void strbuf_add_wrapped_text(struct strbuf *buf,
|
||||||
|
@ -96,9 +96,9 @@ void wt_status_get_state(struct wt_status_state *state, int get_detached_from);
|
|||||||
void wt_shortstatus_print(struct wt_status *s);
|
void wt_shortstatus_print(struct wt_status *s);
|
||||||
void wt_porcelain_print(struct wt_status *s);
|
void wt_porcelain_print(struct wt_status *s);
|
||||||
|
|
||||||
void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...)
|
__attribute__((format (printf, 3, 4)))
|
||||||
;
|
void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...);
|
||||||
void status_printf(struct wt_status *s, const char *color, const char *fmt, ...)
|
__attribute__((format (printf, 3, 4)))
|
||||||
;
|
void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);
|
||||||
|
|
||||||
#endif /* STATUS_H */
|
#endif /* STATUS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user