From 93caf4c7b4e6b7d1f3424263df8ac97397f48d13 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 18 Jul 2014 11:25:41 +1000 Subject: [PATCH] Use GNUC format attribute on print functions Closes #1059 --- src/common/hexchat-plugin.h | 24 ++++++++++++++++++++---- src/common/server.c | 2 +- src/common/server.h | 2 +- src/common/text.c | 4 ++-- src/common/text.h | 4 ++-- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/common/hexchat-plugin.h b/src/common/hexchat-plugin.h index 61597181..002c0c49 100644 --- a/src/common/hexchat-plugin.h +++ b/src/common/hexchat-plugin.h @@ -88,11 +88,19 @@ struct _hexchat_plugin void (*hexchat_print) (hexchat_plugin *ph, const char *text); void (*hexchat_printf) (hexchat_plugin *ph, - const char *format, ...); + const char *format, ...) +#ifdef __GNUC__ + __attribute__((format(printf, 2, 3))) +#endif + ; void (*hexchat_command) (hexchat_plugin *ph, const char *command); void (*hexchat_commandf) (hexchat_plugin *ph, - const char *format, ...); + const char *format, ...) +#ifdef __GNUC__ + __attribute__((format(printf, 2, 3))) +#endif + ; int (*hexchat_nickcmp) (hexchat_plugin *ph, const char *s1, const char *s2); @@ -254,7 +262,11 @@ hexchat_print (hexchat_plugin *ph, void hexchat_printf (hexchat_plugin *ph, - const char *format, ...); + const char *format, ...) +#ifdef __GNUC__ + __attribute__((format(printf, 2, 3))) +#endif +; void hexchat_command (hexchat_plugin *ph, @@ -262,7 +274,11 @@ hexchat_command (hexchat_plugin *ph, void hexchat_commandf (hexchat_plugin *ph, - const char *format, ...); + const char *format, ...) +#ifdef __GNUC__ + __attribute__((format(printf, 2, 3))) +#endif +; int hexchat_nickcmp (hexchat_plugin *ph, diff --git a/src/common/server.c b/src/common/server.c index eea7ce08..98785937 100644 --- a/src/common/server.c +++ b/src/common/server.c @@ -273,7 +273,7 @@ tcp_send (server *serv, char *buf) }*/ void -tcp_sendf (server *serv, char *fmt, ...) +tcp_sendf (server *serv, const char *fmt, ...) { va_list args; /* keep this buffer in BSS. Converting UTF-8 to ISO-8859-x might make the diff --git a/src/common/server.h b/src/common/server.h index 08aeca56..90e9a9c1 100644 --- a/src/common/server.h +++ b/src/common/server.h @@ -25,7 +25,7 @@ extern GSList *serv_list; /* eventually need to keep the tcp_* functions isolated to server.c */ int tcp_send_len (server *serv, char *buf, int len); int tcp_send (server *serv, char *buf); -void tcp_sendf (server *serv, char *fmt, ...); +void tcp_sendf (server *serv, const char *fmt, ...) G_GNUC_PRINTF (2, 3); int tcp_send_real (void *ssl, int sok, char *encoding, int using_irc, char *buf, int len); server *server_new (void); diff --git a/src/common/text.c b/src/common/text.c index ec407833..22467c99 100644 --- a/src/common/text.c +++ b/src/common/text.c @@ -927,7 +927,7 @@ PrintText (session *sess, char *text) } void -PrintTextf (session *sess, char *format, ...) +PrintTextf (session *sess, const char *format, ...) { va_list args; char *buf; @@ -941,7 +941,7 @@ PrintTextf (session *sess, char *format, ...) } void -PrintTextTimeStampf (session *sess, time_t timestamp, char *format, ...) +PrintTextTimeStampf (session *sess, time_t timestamp, const char *format, ...) { va_list args; char *buf; diff --git a/src/common/text.h b/src/common/text.h index a9fd9d4e..9a385167 100644 --- a/src/common/text.h +++ b/src/common/text.h @@ -43,8 +43,8 @@ void scrollback_load (session *sess); int text_word_check (char *word, int len); void PrintText (session *sess, char *text); void PrintTextTimeStamp (session *sess, char *text, time_t timestamp); -void PrintTextf (session *sess, char *format, ...); -void PrintTextTimeStampf (session *sess, time_t timestamp, char *format, ...); +void PrintTextf (session *sess, const char *format, ...) G_GNUC_PRINTF (2, 3); +void PrintTextTimeStampf (session *sess, time_t timestamp, const char *format, ...) G_GNUC_PRINTF (3, 4); void log_close (session *sess); void log_open_or_close (session *sess); void load_text_events (void);