logging: add format checks for printf input
authorHauke Mehrtens <hauke.mehrtens@lantiq.com>
Tue, 22 Sep 2015 14:40:58 +0000 (16:40 +0200)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Wed, 23 Sep 2015 19:41:30 +0000 (19:41 +0000)
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 <hauke.mehrtens@lantiq.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2935
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
resource/csdk/connectivity/common/inc/logger.h
resource/csdk/logger/include/logger.h

index e48ee7c..5e7ff5c 100644 (file)
@@ -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_ */
index 3c69eae..2c85161 100644 (file)
@@ -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