aboutsummaryrefslogtreecommitdiff
path: root/include/pub_tool_libcprint.h
diff options
context:
space:
mode:
authorbart <bart@a5019735-40e9-0310-863c-91ae7b9d1cf9>2008-03-17 18:57:03 +0000
committerbart <bart@a5019735-40e9-0310-863c-91ae7b9d1cf9>2008-03-17 18:57:03 +0000
commitfe101bf01366da80e56c7bd6a3d49d2c157ed10d (patch)
tree728d30a5c737443bb8492bd242d53ebcf6ae65dd /include/pub_tool_libcprint.h
parent3651ec8f5084fee3f64b64732449af2a4fade9ae (diff)
downloadvalgrind-fe101bf01366da80e56c7bd6a3d49d2c157ed10d.tar.gz
Enable compile-time format string checking by gcc if the macro CHECK_FORMAT_STRINGS has been defined before this file has been included.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7731 a5019735-40e9-0310-863c-91ae7b9d1cf9
Diffstat (limited to 'include/pub_tool_libcprint.h')
-rw-r--r--include/pub_tool_libcprint.h34
1 files changed, 23 insertions, 11 deletions
diff --git a/include/pub_tool_libcprint.h b/include/pub_tool_libcprint.h
index 45b5fb47f..8d6770cd7 100644
--- a/include/pub_tool_libcprint.h
+++ b/include/pub_tool_libcprint.h
@@ -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 @@ typedef
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
/*--------------------------------------------------------------------*/