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

Unified Diff: base/string_util_win.h

Issue 9702002: Enable positional parameters for base::vsnprintf and base::vswprintf on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: NULL terminate the beginning of the buffer in case of a failure + a unit test. Created 8 years, 9 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
« no previous file with comments | « no previous file | base/stringprintf_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/string_util_win.h
diff --git a/base/string_util_win.h b/base/string_util_win.h
index 8836f7442299c2252444cf4a2fb830deb1620538..d1addb03fa2da5db9fe015ec2da879f6467afe0f 100644
--- a/base/string_util_win.h
+++ b/base/string_util_win.h
@@ -35,9 +35,12 @@ inline int strncmp16(const char16* s1, const char16* s2, size_t count) {
inline int vsnprintf(char* buffer, size_t size,
const char* format, va_list arguments) {
- int length = vsnprintf_s(buffer, size, size - 1, format, arguments);
- if (length < 0)
- return _vscprintf(format, arguments);
+ int length = _vsprintf_p(buffer, size, format, arguments);
+ if (length < 0) {
+ if (size > 0)
+ buffer[0] = 0;
+ return _vscprintf_p(format, arguments);
+ }
return length;
}
@@ -45,9 +48,12 @@ inline int vswprintf(wchar_t* buffer, size_t size,
const wchar_t* format, va_list arguments) {
DCHECK(IsWprintfFormatPortable(format));
- int length = _vsnwprintf_s(buffer, size, size - 1, format, arguments);
- if (length < 0)
- return _vscwprintf(format, arguments);
+ int length = _vswprintf_p(buffer, size, format, arguments);
+ if (length < 0) {
+ if (size > 0)
+ buffer[0] = 0;
+ return _vscwprintf_p(format, arguments);
+ }
return length;
}
« no previous file with comments | « no previous file | base/stringprintf_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698