From: Hauke Mehrtens Date: Tue, 22 Sep 2015 14:40:58 +0000 (+0200) Subject: logging: add format checks for printf input X-Git-Tag: 1.2.0+RC1~1052 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d72f19fb1ebc0571cc31801e2725976e79a051e7;p=platform%2Fupstream%2Fiotivity.git logging: add format checks for printf input This patch makes gcc aware that this is a function formating a string, this way gcc is able to check if the format string is correct and warn the user otherwise. This should make it possible to find some more problems in the code. Change-Id: I27058eb1d5c3352e6f872e4013eedb94d42d757a Signed-off-by: Hauke Mehrtens Reviewed-on: https://gerrit.iotivity.org/gerrit/2935 Tested-by: jenkins-iotivity Reviewed-by: Patrick Lankswert --- diff --git a/resource/csdk/connectivity/common/inc/logger.h b/resource/csdk/connectivity/common/inc/logger.h index e48ee7ce3..5e7ff5c26 100644 --- a/resource/csdk/connectivity/common/inc/logger.h +++ b/resource/csdk/connectivity/common/inc/logger.h @@ -121,7 +121,11 @@ void OICLog(LogLevel level, const char *tag, const char *logStr); * @param tag - Module name * @param format - variadic log string */ -void OICLogv(LogLevel level, const char *tag, const char *format, ...); +void OICLogv(LogLevel level, const char *tag, const char *format, ...) +#if defined(__GNUC__) + __attribute__ ((format(printf, 3, 4))) +#endif +; /** * Output the contents of the specified buffer (in hex) with the specified priority level. @@ -168,7 +172,11 @@ void OICLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, uint16 * @param format - variadic log string */ void OICLogv(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, - PROGMEM const char *format, ...); + PROGMEM const char *format, ...) +#if defined(__GNUC__) + __attribute__ ((format(printf, 4, 5))) +#endif +; #endif #ifdef TB_LOG @@ -211,4 +219,4 @@ void OICLogv(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, #ifdef __cplusplus } #endif // __cplusplus -#endif /* U_LOGGER_H_ */ \ No newline at end of file +#endif /* U_LOGGER_H_ */ diff --git a/resource/csdk/logger/include/logger.h b/resource/csdk/logger/include/logger.h index 3c69eaee1..2c8516141 100644 --- a/resource/csdk/logger/include/logger.h +++ b/resource/csdk/logger/include/logger.h @@ -105,7 +105,11 @@ typedef enum { * @param tag - Module name * @param format - variadic log string */ - void OCLogv(LogLevel level, const char * tag, const char * format, ...); + void OCLogv(LogLevel level, const char * tag, const char * format, ...) +#if defined(__GNUC__) + __attribute__ ((format(printf, 3, 4))) +#endif + ; /** * Output a log string with the specified priority level. @@ -160,7 +164,11 @@ typedef enum { * @param tag - Module name * @param format - variadic log string */ - void OCLogv(LogLevel level, const char * tag, const char * format, ...); + void OCLogv(LogLevel level, const char * tag, const char * format, ...) +#if defined(__GNUC__) + __attribute__ ((format(printf, 3, 4))) +#endif + ; #endif #ifdef TB_LOG