Commit fc7c8dd8 authored by Nico Weber's avatar Nico Weber Committed by Commit Bot

Remove _Printf_format_string_.

It was only used by MSVC which we no longer use, and it required
including sal.h (somewhat large) in compiler_specific.h (somewhat
commonly included).

clang-cl now no longer needs to process sal.h, which will help
with build times a tiny bit. We still get the format string
protection through the PRINTF_FORMAT macro.

(WPRINTF_FORMAT on the other hand is a no-op and clang-cl
seems to not check wprintf style format strings. So we do
lose some coverage here for wide strings, but we lost that
when we switched to clang-cl.)

TBR=slangley

Bug: none
Change-Id: Iab02869cb06682500ab31e1810c070708347ad64
Reviewed-on: https://chromium-review.googlesource.com/c/1494679
Commit-Queue: Nico Weber <thakis@chromium.org>
Auto-Submit: Nico Weber <thakis@chromium.org>
Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636549}
parent e7428fd1
...@@ -9,9 +9,6 @@ ...@@ -9,9 +9,6 @@
#if defined(COMPILER_MSVC) #if defined(COMPILER_MSVC)
// For _Printf_format_string_.
#include <sal.h>
// Macros for suppressing and disabling warnings on MSVC. // Macros for suppressing and disabling warnings on MSVC.
// //
// Warning numbers are enumerated at: // Warning numbers are enumerated at:
...@@ -33,7 +30,6 @@ ...@@ -33,7 +30,6 @@
#else // Not MSVC #else // Not MSVC
#define _Printf_format_string_
#define MSVC_PUSH_DISABLE_WARNING(n) #define MSVC_PUSH_DISABLE_WARNING(n)
#define MSVC_POP_WARNING() #define MSVC_POP_WARNING()
#define MSVC_DISABLE_OPTIMIZE() #define MSVC_DISABLE_OPTIMIZE()
...@@ -138,6 +134,7 @@ ...@@ -138,6 +134,7 @@
// |dots_param| is the one-based index of the "..." 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. // 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.) // (This is undocumented but matches what the system C headers do.)
// For member functions, the implicit this parameter counts as index 1.
#if defined(COMPILER_GCC) || defined(__clang__) #if defined(COMPILER_GCC) || defined(__clang__)
#define PRINTF_FORMAT(format_param, dots_param) \ #define PRINTF_FORMAT(format_param, dots_param) \
__attribute__((format(printf, format_param, dots_param))) __attribute__((format(printf, format_param, dots_param)))
......
...@@ -41,14 +41,9 @@ int vsnprintf(char* buffer, size_t size, const char* format, va_list arguments) ...@@ -41,14 +41,9 @@ int vsnprintf(char* buffer, size_t size, const char* format, va_list arguments)
// We separate the declaration from the implementation of this inline // We separate the declaration from the implementation of this inline
// function just so the PRINTF_FORMAT works. // function just so the PRINTF_FORMAT works.
inline int snprintf(char* buffer, inline int snprintf(char* buffer, size_t size, const char* format, ...)
size_t size, PRINTF_FORMAT(3, 4);
_Printf_format_string_ const char* format, inline int snprintf(char* buffer, size_t size, const char* format, ...) {
...) PRINTF_FORMAT(3, 4);
inline int snprintf(char* buffer,
size_t size,
_Printf_format_string_ const char* format,
...) {
va_list arguments; va_list arguments;
va_start(arguments, format); va_start(arguments, format);
int result = vsnprintf(buffer, size, format, arguments); int result = vsnprintf(buffer, size, format, arguments);
......
...@@ -16,13 +16,11 @@ ...@@ -16,13 +16,11 @@
namespace base { namespace base {
// Return a C++ string given printf-like input. // Return a C++ string given printf-like input.
BASE_EXPORT std::string StringPrintf(_Printf_format_string_ const char* format, BASE_EXPORT std::string StringPrintf(const char* format, ...)
...)
PRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT; PRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
#if defined(OS_WIN) #if defined(OS_WIN)
BASE_EXPORT std::wstring StringPrintf( BASE_EXPORT std::wstring StringPrintf(const wchar_t* format, ...)
_Printf_format_string_ const wchar_t* format, WPRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
...) WPRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
#endif #endif
// Return a C++ string given vprintf-like input. // Return a C++ string given vprintf-like input.
...@@ -30,25 +28,21 @@ BASE_EXPORT std::string StringPrintV(const char* format, va_list ap) ...@@ -30,25 +28,21 @@ BASE_EXPORT std::string StringPrintV(const char* format, va_list ap)
PRINTF_FORMAT(1, 0) WARN_UNUSED_RESULT; PRINTF_FORMAT(1, 0) WARN_UNUSED_RESULT;
// Store result into a supplied string and return it. // Store result into a supplied string and return it.
BASE_EXPORT const std::string& SStringPrintf( BASE_EXPORT const std::string& SStringPrintf(std::string* dst,
std::string* dst, const char* format,
_Printf_format_string_ const char* format, ...) PRINTF_FORMAT(2, 3);
...) PRINTF_FORMAT(2, 3);
#if defined(OS_WIN) #if defined(OS_WIN)
BASE_EXPORT const std::wstring& SStringPrintf( BASE_EXPORT const std::wstring& SStringPrintf(std::wstring* dst,
std::wstring* dst, const wchar_t* format,
_Printf_format_string_ const wchar_t* format, ...) WPRINTF_FORMAT(2, 3);
...) WPRINTF_FORMAT(2, 3);
#endif #endif
// Append result to a supplied string. // Append result to a supplied string.
BASE_EXPORT void StringAppendF(std::string* dst, BASE_EXPORT void StringAppendF(std::string* dst, const char* format, ...)
_Printf_format_string_ const char* format, PRINTF_FORMAT(2, 3);
...) PRINTF_FORMAT(2, 3);
#if defined(OS_WIN) #if defined(OS_WIN)
BASE_EXPORT void StringAppendF(std::wstring* dst, BASE_EXPORT void StringAppendF(std::wstring* dst, const wchar_t* format, ...)
_Printf_format_string_ const wchar_t* format, WPRINTF_FORMAT(2, 3);
...) WPRINTF_FORMAT(2, 3);
#endif #endif
// Lower-level routine that takes a va_list and appends to a specified // Lower-level routine that takes a va_list and appends to a specified
...@@ -57,8 +51,8 @@ BASE_EXPORT void StringAppendV(std::string* dst, const char* format, va_list ap) ...@@ -57,8 +51,8 @@ BASE_EXPORT void StringAppendV(std::string* dst, const char* format, va_list ap)
PRINTF_FORMAT(2, 0); PRINTF_FORMAT(2, 0);
#if defined(OS_WIN) #if defined(OS_WIN)
BASE_EXPORT void StringAppendV(std::wstring* dst, BASE_EXPORT void StringAppendV(std::wstring* dst,
const wchar_t* format, va_list ap) const wchar_t* format,
WPRINTF_FORMAT(2, 0); va_list ap) WPRINTF_FORMAT(2, 0);
#endif #endif
} // namespace base } // namespace base
......
...@@ -24,7 +24,7 @@ void ClearLog(); ...@@ -24,7 +24,7 @@ void ClearLog();
// This function can be called from any thread. // This function can be called from any thread.
void Log(logging::LogSeverity level, void Log(logging::LogSeverity level,
const base::Location& location, const base::Location& location,
_Printf_format_string_ const char* format, const char* format,
...) PRINTF_FORMAT(3, 4); ...) PRINTF_FORMAT(3, 4);
// Returns the log history. // Returns the log history.
......
...@@ -46,9 +46,8 @@ class EventLogger { ...@@ -46,9 +46,8 @@ class EventLogger {
// Logs a message with formatting. // Logs a message with formatting.
// Can be called from any thread as long as the object is alive. // Can be called from any thread as long as the object is alive.
void Log(logging::LogSeverity severity, void Log(logging::LogSeverity severity, const char* format, ...)
_Printf_format_string_ const char* format, PRINTF_FORMAT(3, 4);
...) PRINTF_FORMAT(3, 4);
// Sets the history size. The existing history is cleared. // Sets the history size. The existing history is cleared.
// Can be called from any thread as long as the object is alive. // Can be called from any thread as long as the object is alive.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment