summaryrefslogtreecommitdiffstats
path: root/base/compiler_specific.h
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-20 06:53:28 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-20 06:53:28 +0000
commit34b2b007db875a6acb853c5cd2a247fbb32c0f88 (patch)
tree6dc39bc9f10d6e8eedcdf14821ba9e96b5ccab51 /base/compiler_specific.h
parent24b857793e27aded8d804a112a5fe6c77e28b081 (diff)
downloadchromium_src-34b2b007db875a6acb853c5cd2a247fbb32c0f88.zip
chromium_src-34b2b007db875a6acb853c5cd2a247fbb32c0f88.tar.gz
chromium_src-34b2b007db875a6acb853c5cd2a247fbb32c0f88.tar.bz2
Add compiler-specific "examine printf format" attributes to printfs.
Functions that take a printf-style format get a new annotation, which produces a bunch of compiler warnings when you use printf impoperly. This change adds the annotations and fixes the warnings. We now must use PRId64 for 64-bit numbers and the PRIsz for size_t. Review URL: http://codereview.chromium.org/339059 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32600 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/compiler_specific.h')
-rw-r--r--base/compiler_specific.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/base/compiler_specific.h b/base/compiler_specific.h
index 50dc6f3..23b9f124 100644
--- a/base/compiler_specific.h
+++ b/base/compiler_specific.h
@@ -67,11 +67,32 @@
#if defined(COMPILER_GCC)
+
#define ALLOW_UNUSED __attribute__((unused))
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
+
+// Tell the compiler a function is using a printf-style format string.
+// |format_param| is the one-based index of the format string parameter;
+// |dots_param| is the one-based index of the "..." parameter.
+// For v*printf functions (which take a va_list), pass 0 for dots_param.
+// (This is undocumented but matches what the system C headers do.)
+#define PRINTF_FORMAT(format_param, dots_param) \
+ __attribute__((format(printf, format_param, dots_param)))
+
+// WPRINTF_FORMAT is the same, but for wide format strings.
+// This doesn't appear to yet be implemented.
+// See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38308 .
+#define WPRINTF_FORMAT(format_param, dots_param)
+// If available, it would look like:
+// __attribute__((format(wprintf, format_param, dots_param)))
+
#else // Not GCC
+
#define ALLOW_UNUSED
#define WARN_UNUSED_RESULT
+#define PRINTF_FORMAT(x, y)
+#define WPRINTF_FORMAT(x, y)
+
#endif
#endif // BASE_COMPILER_SPECIFIC_H_