|
From: <sv...@va...> - 2008-03-17 18:57:02
|
Author: bart Date: 2008-03-17 18:57:03 +0000 (Mon, 17 Mar 2008) New Revision: 7731 Log: Enable compile-time format string checking by gcc if the macro CHECK_FORMAT_STRINGS has been defined before this file has been included. Modified: trunk/include/pub_tool_libcprint.h Modified: trunk/include/pub_tool_libcprint.h =================================================================== --- trunk/include/pub_tool_libcprint.h 2008-03-17 18:38:26 UTC (rev 7730) +++ trunk/include/pub_tool_libcprint.h 2008-03-17 18:57:03 UTC (rev 7731) @@ -31,6 +31,21 @@ #ifndef __PUB_TOOL_LIBCPRINT_H #define __PUB_TOOL_LIBCPRINT_H + +/* Enable compile-time format string checking by gcc if the macro + CHECK_FORMAT_STRINGS has been defined before this file has been included. + This feature is supported since at least gcc version 2.95. + For more information about the format attribute, see also + http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Function-Attributes.html. + */ + +#if defined(__GNUC__) && defined(CHECK_FORMAT_STRINGS) +#define PRINTF_CHECK(x, y) __attribute__((format(__printf__, x, y))) +#else +#define PRINTF_CHECK(x, y) +#endif + + /* --------------------------------------------------------------------- Basic printing ------------------------------------------------------------------ */ @@ -39,17 +54,14 @@ * --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_(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_(vsprintf) ( Char* buf, const HChar* format, va_list vargs ); - +extern UInt VG_(printf) ( const HChar *format, ... ) PRINTF_CHECK(1, 2); +extern UInt VG_(vprintf) ( const HChar *format, va_list vargs ) PRINTF_CHECK(1, 0); +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 ) PRINTF_CHECK(2, 0); 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 ); + const HChar *format, va_list vargs ) PRINTF_CHECK(3, 0); // Percentify n/m with d decimal places. Includes the '%' symbol at the end. // Right justifies in 'buf'. @@ -74,9 +86,9 @@ VgMsgKind; /* Send a single-part message. Appends a newline. */ -extern UInt VG_(message) ( VgMsgKind kind, const HChar* format, ... ); -extern UInt VG_(vmessage) ( VgMsgKind kind, const HChar* format, va_list vargs ); +extern UInt VG_(message) ( VgMsgKind kind, const HChar* format, ... ) PRINTF_CHECK(2, 3); +extern UInt VG_(vmessage) ( VgMsgKind kind, const HChar* format, va_list vargs ) PRINTF_CHECK(2, 0); #endif // __PUB_TOOL_LIBCPRINT_H /*--------------------------------------------------------------------*/ |