Page 1 of 1

chprintf Argument Checking with gcc

Posted: Mon Apr 23, 2012 6:25 pm
by efs113
Hi All,

gcc has the capability to check arguments on printf() like functions. The patch below adds this ability to chprintf() when using gcc. As chprintf() doesn't support the full printf() format, it won't catch everything, but it will warn if you pass an int type for a '%s', have too many/few arguments, etc ...

Code: Select all

Index: os/various/chprintf.h
===================================================================
--- os/various/chprintf.h   (revision 865)
+++ os/various/chprintf.h   (working copy)
@@ -39,7 +39,11 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
+#ifdef __GNUC__
+  void chprintf(BaseChannel *chp, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
+#else
   void chprintf(BaseChannel *chp, const char *fmt, ...);
+#endif
 #ifdef __cplusplus
 }
 #endif


Eric

Re: chprintf Argument Checking with gcc

Posted: Mon Apr 23, 2012 6:31 pm
by Giovanni
Hi Eric,

Thanks for the patch, very useful, I will merge it.

Giovanni