Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3017)

Unified Diff: base/strings/stringprintf.h

Issue 1372153002: Detecting and fixing stringprintf.h format bugs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed four mismatches that I missed Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/strings/stringprintf.h
diff --git a/base/strings/stringprintf.h b/base/strings/stringprintf.h
index 523f7ee55bf3693895b2d2d43d73f1c50565cb12..9ea4ce51f97106d1eb33c1b0100d5ec408ae9fff 100644
--- a/base/strings/stringprintf.h
+++ b/base/strings/stringprintf.h
@@ -7,6 +7,13 @@
#include <stdarg.h> // va_list
+#ifdef _MSC_VER
Lei Zhang 2015/09/29 03:16:17 Check against COMPILER_MSVC instead? This is somet
brucedawson 2015/09/29 21:39:39 I'm not sure what the best check is. The need for
Lei Zhang 2015/09/29 21:42:37 There's no hard rule, but in non-third-party code,
+// For _Printf_format_string_
+#include <sal.h>
+#else
+// For nacl builds
+#define _Printf_format_string_
+#endif
#include <string>
#include "base/base_export.h"
@@ -15,11 +22,13 @@
namespace base {
// Return a C++ string given printf-like input.
-BASE_EXPORT std::string StringPrintf(const char* format, ...)
+BASE_EXPORT std::string StringPrintf(_Printf_format_string_ const char* format,
+ ...)
PRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
#if defined(OS_WIN)
-BASE_EXPORT std::wstring StringPrintf(const wchar_t* format, ...)
- WPRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
+BASE_EXPORT std::wstring StringPrintf(
+ _Printf_format_string_ const wchar_t* format,
+ ...) WPRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
#endif
// Return a C++ string given vprintf-like input.
@@ -27,21 +36,25 @@ BASE_EXPORT std::string StringPrintV(const char* format, va_list ap)
PRINTF_FORMAT(1, 0) WARN_UNUSED_RESULT;
// Store result into a supplied string and return it.
-BASE_EXPORT const std::string& SStringPrintf(std::string* dst,
- const char* format, ...)
- PRINTF_FORMAT(2, 3);
+BASE_EXPORT const std::string& SStringPrintf(
+ std::string* dst,
+ _Printf_format_string_ const char* format,
+ ...) PRINTF_FORMAT(2, 3);
#if defined(OS_WIN)
-BASE_EXPORT const std::wstring& SStringPrintf(std::wstring* dst,
- const wchar_t* format, ...)
- WPRINTF_FORMAT(2, 3);
+BASE_EXPORT const std::wstring& SStringPrintf(
+ std::wstring* dst,
+ _Printf_format_string_ const wchar_t* format,
+ ...) WPRINTF_FORMAT(2, 3);
#endif
// Append result to a supplied string.
-BASE_EXPORT void StringAppendF(std::string* dst, const char* format, ...)
- PRINTF_FORMAT(2, 3);
+BASE_EXPORT void StringAppendF(std::string* dst,
+ _Printf_format_string_ const char* format,
+ ...) PRINTF_FORMAT(2, 3);
#if defined(OS_WIN)
-BASE_EXPORT void StringAppendF(std::wstring* dst, const wchar_t* format, ...)
- WPRINTF_FORMAT(2, 3);
+BASE_EXPORT void StringAppendF(std::wstring* dst,
+ _Printf_format_string_ const wchar_t* format,
+ ...) WPRINTF_FORMAT(2, 3);
#endif
// Lower-level routine that takes a va_list and appends to a specified

Powered by Google App Engine
This is Rietveld 408576698