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

Side by Side Diff: base/strings/stringprintf.cc

Issue 812543002: Update from https://crrev.com/308331 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « base/strings/string_util_unittest.cc ('k') | base/strings/sys_string_conversions_posix.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 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 #include "base/strings/stringprintf.h" 5 #include "base/strings/stringprintf.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "base/scoped_clear_errno.h" 9 #include "base/scoped_clear_errno.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 30 matching lines...) Expand all
41 template <class StringType> 41 template <class StringType>
42 static void StringAppendVT(StringType* dst, 42 static void StringAppendVT(StringType* dst,
43 const typename StringType::value_type* format, 43 const typename StringType::value_type* format,
44 va_list ap) { 44 va_list ap) {
45 // First try with a small fixed size buffer. 45 // First try with a small fixed size buffer.
46 // This buffer size should be kept in sync with StringUtilTest.GrowBoundary 46 // This buffer size should be kept in sync with StringUtilTest.GrowBoundary
47 // and StringUtilTest.StringPrintfBounds. 47 // and StringUtilTest.StringPrintfBounds.
48 typename StringType::value_type stack_buf[1024]; 48 typename StringType::value_type stack_buf[1024];
49 49
50 va_list ap_copy; 50 va_list ap_copy;
51 GG_VA_COPY(ap_copy, ap); 51 va_copy(ap_copy, ap);
52 52
53 #if !defined(OS_WIN) 53 #if !defined(OS_WIN)
54 ScopedClearErrno clear_errno; 54 ScopedClearErrno clear_errno;
55 #endif 55 #endif
56 int result = vsnprintfT(stack_buf, arraysize(stack_buf), format, ap_copy); 56 int result = vsnprintfT(stack_buf, arraysize(stack_buf), format, ap_copy);
57 va_end(ap_copy); 57 va_end(ap_copy);
58 58
59 if (result >= 0 && result < static_cast<int>(arraysize(stack_buf))) { 59 if (result >= 0 && result < static_cast<int>(arraysize(stack_buf))) {
60 // It fit. 60 // It fit.
61 dst->append(stack_buf, result); 61 dst->append(stack_buf, result);
(...skipping 25 matching lines...) Expand all
87 // against huge allocations when using vsnprintfT implementations that 87 // against huge allocations when using vsnprintfT implementations that
88 // return -1 for reasons other than overflow without setting errno. 88 // return -1 for reasons other than overflow without setting errno.
89 DLOG(WARNING) << "Unable to printf the requested string due to size."; 89 DLOG(WARNING) << "Unable to printf the requested string due to size.";
90 return; 90 return;
91 } 91 }
92 92
93 std::vector<typename StringType::value_type> mem_buf(mem_length); 93 std::vector<typename StringType::value_type> mem_buf(mem_length);
94 94
95 // NOTE: You can only use a va_list once. Since we're in a while loop, we 95 // NOTE: You can only use a va_list once. Since we're in a while loop, we
96 // need to make a new copy each time so we don't use up the original. 96 // need to make a new copy each time so we don't use up the original.
97 GG_VA_COPY(ap_copy, ap); 97 va_copy(ap_copy, ap);
98 result = vsnprintfT(&mem_buf[0], mem_length, format, ap_copy); 98 result = vsnprintfT(&mem_buf[0], mem_length, format, ap_copy);
99 va_end(ap_copy); 99 va_end(ap_copy);
100 100
101 if ((result >= 0) && (result < mem_length)) { 101 if ((result >= 0) && (result < mem_length)) {
102 // It fit. 102 // It fit.
103 dst->append(&mem_buf[0], result); 103 dst->append(&mem_buf[0], result);
104 return; 104 return;
105 } 105 }
106 } 106 }
107 } 107 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 StringAppendVT(dst, format, ap); 175 StringAppendVT(dst, format, ap);
176 } 176 }
177 177
178 #if !defined(OS_ANDROID) 178 #if !defined(OS_ANDROID)
179 void StringAppendV(std::wstring* dst, const wchar_t* format, va_list ap) { 179 void StringAppendV(std::wstring* dst, const wchar_t* format, va_list ap) {
180 StringAppendVT(dst, format, ap); 180 StringAppendVT(dst, format, ap);
181 } 181 }
182 #endif 182 #endif
183 183
184 } // namespace base 184 } // namespace base
OLDNEW
« no previous file with comments | « base/strings/string_util_unittest.cc ('k') | base/strings/sys_string_conversions_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698