From b1527b7947b867a8dc6dd22bda9147713c10620b Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Tue, 21 Jun 2016 16:30:16 -0700 Subject: [PATCH] Check string format in log_message Move "printflike" definition to arch.h, it's used both by log.h and os_calls.h. --- common/arch.h | 12 ++++++++++++ common/log.h | 2 +- common/os_calls.h | 11 ----------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/common/arch.h b/common/arch.h index d3ae460e..5c67cb66 100644 --- a/common/arch.h +++ b/common/arch.h @@ -19,6 +19,10 @@ #if !defined(ARCH_H) #define ARCH_H +#if defined(HAVE_CONFIG_H) +#include "config_ac.h" +#endif + /* you can define L_ENDIAN or B_ENDIAN and NEED_ALIGN or NO_NEED_ALIGN in the makefile to override */ @@ -125,4 +129,12 @@ typedef signed long long tsi64; #endif #endif /* DEFINED_Ts */ +/* format string verification */ +#if defined(HAVE_FUNC_ATTRIBUTE_FORMAT) +#define printflike(arg_format, arg_first_check) \ + __attribute__((__format__(__printf__, arg_format, arg_first_check))) +#else +#define printflike(arg_format, arg_first_check) +#endif + #endif diff --git a/common/log.h b/common/log.h index 15307588..6654028b 100644 --- a/common/log.h +++ b/common/log.h @@ -171,7 +171,7 @@ log_end(void); * @return */ enum logReturns DEFAULT_CC -log_message(const enum logLevels lvl, const char *msg, ...); +log_message(const enum logLevels lvl, const char *msg, ...) printflike(2, 3); /** * diff --git a/common/os_calls.h b/common/os_calls.h index 2ed2cb81..0a58d4a8 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -21,10 +21,6 @@ #if !defined(OS_CALLS_H) #define OS_CALLS_H -#if defined(HAVE_CONFIG_H) -#include "config_ac.h" -#endif - #ifndef NULL #define NULL 0 #endif @@ -45,13 +41,6 @@ #define g_tcp_select g_sck_select #define g_close_wait_obj g_delete_wait_obj -#if defined(HAVE_FUNC_ATTRIBUTE_FORMAT) -#define printflike(arg_format, arg_first_check) \ - __attribute__((__format__(__printf__, arg_format, arg_first_check))) -#else -#define printflike(arg_format, arg_first_check) -#endif - int APP_CC g_rm_temp_dir(void); int APP_CC g_mk_temp_dir(const char* app_name); void APP_CC g_init(const char* app_name);