From fdeeb6f8547617a0478ffe847b76c46fa45487d0 Mon Sep 17 00:00:00 2001 From: Guillaume Nault Date: Tue, 4 Sep 2012 20:29:08 +0200 Subject: Add compilation checks for printf-style format strings Append the format() __attribute__ to function prototypes which use a format string. This allows GCC to check for consistency between the format string and its arguments when these functions are called. Signed-off-by: Guillaume Nault --- accel-pppd/cli/cli.h | 2 +- accel-pppd/log.h | 30 +++++++++++++++--------------- accel-pppd/triton/triton_p.h | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/accel-pppd/cli/cli.h b/accel-pppd/cli/cli.h index 3e31c5d8..1fbb985e 100644 --- a/accel-pppd/cli/cli.h +++ b/accel-pppd/cli/cli.h @@ -42,7 +42,7 @@ void cli_register_regexp_cmd(struct cli_regexp_cmd_t *cmd); void cli_show_ses_register(const char *name, const char *desc, void (*print)(const struct ap_session *ses, char *buf)); int cli_send(void *client, const char *data); -int cli_sendv(void *client, const char *fmt, ...); +int cli_sendv(void *client, const char *fmt, ...) __attribute__((format(gnu_printf, 2, 3))); #endif diff --git a/accel-pppd/log.h b/accel-pppd/log.h index 2ff2ac80..0b4c1cee 100644 --- a/accel-pppd/log.h +++ b/accel-pppd/log.h @@ -39,21 +39,21 @@ struct log_target_t void log_free_msg(struct log_msg_t *msg); -void log_emerg(const char *fmt, ...); - -void log_error(const char *fmt,...); -void log_warn(const char *fmt,...); -void log_info1(const char *fmt,...); -void log_info2(const char *fmt,...); -void log_debug(const char *fmt,...); -void log_msg(const char *fmt,...); - -void log_ppp_error(const char *fmt,...); -void log_ppp_warn(const char *fmt,...); -void log_ppp_info1(const char *fmt,...); -void log_ppp_info2(const char *fmt,...); -void log_ppp_debug(const char *fmt,...); -void log_ppp_msg(const char *fmt,...); +void log_emerg(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); + +void log_error(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); +void log_warn(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); +void log_info1(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); +void log_info2(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); +void log_debug(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); +void log_msg(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); + +void log_ppp_error(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); +void log_ppp_warn(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); +void log_ppp_info1(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); +void log_ppp_info2(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); +void log_ppp_debug(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); +void log_ppp_msg(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); void log_switch(struct triton_context_t *ctx, void *arg); diff --git a/accel-pppd/triton/triton_p.h b/accel-pppd/triton/triton_p.h index 2eb2e62a..443cedea 100644 --- a/accel-pppd/triton/triton_p.h +++ b/accel-pppd/triton/triton_p.h @@ -104,8 +104,8 @@ int triton_queue_ctx(struct _triton_context_t*); void triton_thread_wakeup(struct _triton_thread_t*); int conf_load(const char *fname); int conf_reload(const char *fname); -void triton_log_error(const char *fmt,...); -void triton_log_debug(const char *fmt,...); +void triton_log_error(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); +void triton_log_debug(const char *fmt, ...) __attribute__((format(gnu_printf, 1, 2))); int load_modules(const char *name); #endif -- cgit v1.2.3