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

Side by Side Diff: base/stringprintf.cc

Issue 14749003: Stop overwriting errno in base::StringPrintf, StringAppendV, and StringToDouble (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comment Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « base/scoped_clear_errno_unittest.cc ('k') | base/stringprintf_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/stringprintf.h" 5 #include "base/stringprintf.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "base/scoped_clear_errno.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 12
12 namespace base { 13 namespace base {
13 14
14 namespace { 15 namespace {
15 16
16 // Overloaded wrappers around vsnprintf and vswprintf. The buf_size parameter 17 // Overloaded wrappers around vsnprintf and vswprintf. The buf_size parameter
17 // is the size of the buffer. These return the number of characters in the 18 // is the size of the buffer. These return the number of characters in the
18 // formatted string excluding the NUL terminator. If the buffer is not 19 // formatted string excluding the NUL terminator. If the buffer is not
(...skipping 24 matching lines...) Expand all
43 va_list ap) { 44 va_list ap) {
44 // First try with a small fixed size buffer. 45 // First try with a small fixed size buffer.
45 // This buffer size should be kept in sync with StringUtilTest.GrowBoundary 46 // This buffer size should be kept in sync with StringUtilTest.GrowBoundary
46 // and StringUtilTest.StringPrintfBounds. 47 // and StringUtilTest.StringPrintfBounds.
47 typename StringType::value_type stack_buf[1024]; 48 typename StringType::value_type stack_buf[1024];
48 49
49 va_list ap_copy; 50 va_list ap_copy;
50 GG_VA_COPY(ap_copy, ap); 51 GG_VA_COPY(ap_copy, ap);
51 52
52 #if !defined(OS_WIN) 53 #if !defined(OS_WIN)
53 errno = 0; 54 ScopedClearErrno clear_errno;
54 #endif 55 #endif
55 int result = vsnprintfT(stack_buf, arraysize(stack_buf), format, ap_copy); 56 int result = vsnprintfT(stack_buf, arraysize(stack_buf), format, ap_copy);
56 va_end(ap_copy); 57 va_end(ap_copy);
57 58
58 if (result >= 0 && result < static_cast<int>(arraysize(stack_buf))) { 59 if (result >= 0 && result < static_cast<int>(arraysize(stack_buf))) {
59 // It fit. 60 // It fit.
60 dst->append(stack_buf, result); 61 dst->append(stack_buf, result);
61 return; 62 return;
62 } 63 }
63 64
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 StringAppendVT(dst, format, ap); 177 StringAppendVT(dst, format, ap);
177 } 178 }
178 179
179 #if !defined(OS_ANDROID) 180 #if !defined(OS_ANDROID)
180 void StringAppendV(std::wstring* dst, const wchar_t* format, va_list ap) { 181 void StringAppendV(std::wstring* dst, const wchar_t* format, va_list ap) {
181 StringAppendVT(dst, format, ap); 182 StringAppendVT(dst, format, ap);
182 } 183 }
183 #endif 184 #endif
184 185
185 } // namespace base 186 } // namespace base
OLDNEW
« no previous file with comments | « base/scoped_clear_errno_unittest.cc ('k') | base/stringprintf_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698