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

Side by Side 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, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_STRINGS_STRINGPRINTF_H_ 5 #ifndef BASE_STRINGS_STRINGPRINTF_H_
6 #define BASE_STRINGS_STRINGPRINTF_H_ 6 #define BASE_STRINGS_STRINGPRINTF_H_
7 7
8 #include <stdarg.h> // va_list 8 #include <stdarg.h> // va_list
9 9
10 #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,
11 // For _Printf_format_string_
12 #include <sal.h>
13 #else
14 // For nacl builds
15 #define _Printf_format_string_
16 #endif
10 #include <string> 17 #include <string>
11 18
12 #include "base/base_export.h" 19 #include "base/base_export.h"
13 #include "base/compiler_specific.h" 20 #include "base/compiler_specific.h"
14 21
15 namespace base { 22 namespace base {
16 23
17 // Return a C++ string given printf-like input. 24 // Return a C++ string given printf-like input.
18 BASE_EXPORT std::string StringPrintf(const char* format, ...) 25 BASE_EXPORT std::string StringPrintf(_Printf_format_string_ const char* format,
26 ...)
19 PRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT; 27 PRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
20 #if defined(OS_WIN) 28 #if defined(OS_WIN)
21 BASE_EXPORT std::wstring StringPrintf(const wchar_t* format, ...) 29 BASE_EXPORT std::wstring StringPrintf(
22 WPRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT; 30 _Printf_format_string_ const wchar_t* format,
31 ...) WPRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
23 #endif 32 #endif
24 33
25 // Return a C++ string given vprintf-like input. 34 // Return a C++ string given vprintf-like input.
26 BASE_EXPORT std::string StringPrintV(const char* format, va_list ap) 35 BASE_EXPORT std::string StringPrintV(const char* format, va_list ap)
27 PRINTF_FORMAT(1, 0) WARN_UNUSED_RESULT; 36 PRINTF_FORMAT(1, 0) WARN_UNUSED_RESULT;
28 37
29 // Store result into a supplied string and return it. 38 // Store result into a supplied string and return it.
30 BASE_EXPORT const std::string& SStringPrintf(std::string* dst, 39 BASE_EXPORT const std::string& SStringPrintf(
31 const char* format, ...) 40 std::string* dst,
32 PRINTF_FORMAT(2, 3); 41 _Printf_format_string_ const char* format,
42 ...) PRINTF_FORMAT(2, 3);
33 #if defined(OS_WIN) 43 #if defined(OS_WIN)
34 BASE_EXPORT const std::wstring& SStringPrintf(std::wstring* dst, 44 BASE_EXPORT const std::wstring& SStringPrintf(
35 const wchar_t* format, ...) 45 std::wstring* dst,
36 WPRINTF_FORMAT(2, 3); 46 _Printf_format_string_ const wchar_t* format,
47 ...) WPRINTF_FORMAT(2, 3);
37 #endif 48 #endif
38 49
39 // Append result to a supplied string. 50 // Append result to a supplied string.
40 BASE_EXPORT void StringAppendF(std::string* dst, const char* format, ...) 51 BASE_EXPORT void StringAppendF(std::string* dst,
41 PRINTF_FORMAT(2, 3); 52 _Printf_format_string_ const char* format,
53 ...) PRINTF_FORMAT(2, 3);
42 #if defined(OS_WIN) 54 #if defined(OS_WIN)
43 BASE_EXPORT void StringAppendF(std::wstring* dst, const wchar_t* format, ...) 55 BASE_EXPORT void StringAppendF(std::wstring* dst,
44 WPRINTF_FORMAT(2, 3); 56 _Printf_format_string_ const wchar_t* format,
57 ...) WPRINTF_FORMAT(2, 3);
45 #endif 58 #endif
46 59
47 // Lower-level routine that takes a va_list and appends to a specified 60 // Lower-level routine that takes a va_list and appends to a specified
48 // string. All other routines are just convenience wrappers around it. 61 // string. All other routines are just convenience wrappers around it.
49 BASE_EXPORT void StringAppendV(std::string* dst, const char* format, va_list ap) 62 BASE_EXPORT void StringAppendV(std::string* dst, const char* format, va_list ap)
50 PRINTF_FORMAT(2, 0); 63 PRINTF_FORMAT(2, 0);
51 #if defined(OS_WIN) 64 #if defined(OS_WIN)
52 BASE_EXPORT void StringAppendV(std::wstring* dst, 65 BASE_EXPORT void StringAppendV(std::wstring* dst,
53 const wchar_t* format, va_list ap) 66 const wchar_t* format, va_list ap)
54 WPRINTF_FORMAT(2, 0); 67 WPRINTF_FORMAT(2, 0);
55 #endif 68 #endif
56 69
57 } // namespace base 70 } // namespace base
58 71
59 #endif // BASE_STRINGS_STRINGPRINTF_H_ 72 #endif // BASE_STRINGS_STRINGPRINTF_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698