|
From: <sv...@va...> - 2007-09-24 13:25:24
|
Author: dirk
Date: 2007-09-24 14:25:24 +0100 (Mon, 24 Sep 2007)
New Revision: 6909
Log:
add format argument checking. might find useful portability issues
Modified:
trunk/include/pub_tool_libcprint.h
Modified: trunk/include/pub_tool_libcprint.h
===================================================================
--- trunk/include/pub_tool_libcprint.h 2007-09-24 13:24:50 UTC (rev 6908)
+++ trunk/include/pub_tool_libcprint.h 2007-09-24 13:25:24 UTC (rev 6909)
@@ -35,19 +35,26 @@
Basic printing
------------------------------------------------------------------ */
+#ifdef __GNUC__
+# define PRINTF_CHECK(x,y) __attribute__((format(__printf__, x, y)))
+#else
+# define PRINTF_CHECK(x,y) /* x, y */
+#endif
+
/* Note that they all output to the file descriptor given by the
* --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr).
* Hence no need for VG_(fprintf)().
*/
-extern UInt VG_(printf) ( const HChar *format, ... );
+
+extern UInt VG_(printf) ( const HChar *format, ... ) PRINTF_CHECK(1,2);
extern UInt VG_(vprintf) ( const HChar *format, va_list vargs );
/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
-extern UInt VG_(sprintf) ( Char* buf, const HChar* format, ... );
+extern UInt VG_(sprintf) ( Char* buf, const HChar* format, ... ) PRINTF_CHECK(2,3);
extern UInt VG_(vsprintf) ( Char* buf, const HChar* format, va_list vargs );
extern UInt VG_(snprintf) ( Char* buf, Int size,
- const HChar *format, ... );
+ const HChar *format, ... ) PRINTF_CHECK(3,4);
extern UInt VG_(vsnprintf)( Char* buf, Int size,
const HChar *format, va_list vargs );
|
|
From: Nicholas N. <nj...@cs...> - 2007-09-26 03:19:09
|
On Mon, 24 Sep 2007 sv...@va... wrote: > Log: > add format argument checking. might find useful portability issues That causes *lots* of warnings. Will you have a chance to work on fixing them? Nick |
|
From: Florian K. <br...@ac...> - 2007-09-26 04:48:46
|
On Tuesday 25 September 2007 11:19 pm, Nicholas Nethercote wrote: > On Mon, 24 Sep 2007 sv...@va... wrote: > > Log: > > add format argument checking. might find useful portability issues > > That causes *lots* of warnings. Will you have a chance to work on fixing > them? > This warning: int format, UWord arg is fixed by a patch I had sent two weeks ago or so.. The other one: format argument is not a pointer .. I think you agreed to not fix that which suggests that -Wformat should probably not be enabled by default. But you could still use it occasionally and grep the build log to find the format inconsistencies that you're interested in.. Florian |
|
From: Dirk M. <dm...@gm...> - 2007-09-26 09:44:47
|
On Wednesday, 26. September 2007, Nicholas Nethercote wrote: > > add format argument checking. might find useful portability issues > That causes *lots* of warnings. Will you have a chance to work on fixing > them? Yes, I`ll go through them step by step and clean it up. Is there a particular urgency? If so, I can just revert the patch again. I think its still more important to have the warning in order to not introduce further issues in the future. Thanks, Dirk |
|
From: Bart V. A. <bar...@gm...> - 2007-09-26 06:52:34
|
In my opinion enabling gcc's format argument checking for Valgrind source code is a bad idea: Valgrind's format specifications are not identical to the ANSI C format specifications. Valgrind e.g. supports format specifications like "%,d", which are not allowed by ANSI C. For an example of code that uses this kind of format specifications, see e.g. memcheck/mc_malloc_wrappers.c. Bart. On 9/24/07, sv...@va... < sv...@va...> wrote: > > Author: dirk > Date: 2007-09-24 14:25:24 +0100 (Mon, 24 Sep 2007) > New Revision: 6909 > > Log: > add format argument checking. might find useful portability issues > > Modified: > trunk/include/pub_tool_libcprint.h > > > Modified: trunk/include/pub_tool_libcprint.h > =================================================================== > --- trunk/include/pub_tool_libcprint.h 2007-09-24 13:24:50 UTC (rev 6908) > +++ trunk/include/pub_tool_libcprint.h 2007-09-24 13:25:24 UTC (rev 6909) > > @@ -35,19 +35,26 @@ > Basic printing > ------------------------------------------------------------------ */ > > +#ifdef __GNUC__ > +# define PRINTF_CHECK(x,y) __attribute__((format(__printf__, x, y))) > +#else > +# define PRINTF_CHECK(x,y) /* x, y */ > +#endif > + > /* Note that they all output to the file descriptor given by the > * --log-fd/--log-file/--log-socket argument, which defaults to 2 > (stderr). > * Hence no need for VG_(fprintf)(). > */ > -extern UInt VG_(printf) ( const HChar *format, ... ); > + > +extern UInt VG_(printf) ( const HChar *format, ... ) PRINTF_CHECK(1,2); > extern UInt VG_(vprintf) ( const HChar *format, va_list vargs ); > /* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */ > > -extern UInt VG_(sprintf) ( Char* buf, const HChar* format, ... ); > +extern UInt VG_(sprintf) ( Char* buf, const HChar* format, ... ) > PRINTF_CHECK(2,3); > extern UInt VG_(vsprintf) ( Char* buf, const HChar* format, va_list vargs > ); > > extern UInt VG_(snprintf) ( Char* buf, Int size, > - const HChar *format, ... ); > + const HChar *format, ... ) > PRINTF_CHECK(3,4); > extern UInt VG_(vsnprintf)( Char* buf, Int size, > const HChar *format, va_list vargs > ); > |