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

Side by Side Diff: base/string_util.cc

Issue 160191: Move base::va_copy from a function to a macro. (Closed)
Patch Set: Created 11 years, 5 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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/string_util.h" 5 #include "base/string_util.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <ctype.h> 9 #include <ctype.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 template <class StringType> 908 template <class StringType>
909 static void StringAppendVT(StringType* dst, 909 static void StringAppendVT(StringType* dst,
910 const typename StringType::value_type* format, 910 const typename StringType::value_type* format,
911 va_list ap) { 911 va_list ap) {
912 // First try with a small fixed size buffer. 912 // First try with a small fixed size buffer.
913 // This buffer size should be kept in sync with StringUtilTest.GrowBoundary 913 // This buffer size should be kept in sync with StringUtilTest.GrowBoundary
914 // and StringUtilTest.StringPrintfBounds. 914 // and StringUtilTest.StringPrintfBounds.
915 typename StringType::value_type stack_buf[1024]; 915 typename StringType::value_type stack_buf[1024];
916 916
917 va_list backup_ap; 917 va_list backup_ap;
918 base::va_copy(backup_ap, ap); 918 GG_VA_COPY(backup_ap, ap);
919 919
920 #if !defined(OS_WIN) 920 #if !defined(OS_WIN)
921 errno = 0; 921 errno = 0;
922 #endif 922 #endif
923 int result = vsnprintfT(stack_buf, arraysize(stack_buf), format, backup_ap); 923 int result = vsnprintfT(stack_buf, arraysize(stack_buf), format, backup_ap);
924 va_end(backup_ap); 924 va_end(backup_ap);
925 925
926 if (result >= 0 && result < static_cast<int>(arraysize(stack_buf))) { 926 if (result >= 0 && result < static_cast<int>(arraysize(stack_buf))) {
927 // It fit. 927 // It fit.
928 dst->append(stack_buf, result); 928 dst->append(stack_buf, result);
(...skipping 26 matching lines...) Expand all
955 // That should be plenty, don't try anything larger. This protects 955 // That should be plenty, don't try anything larger. This protects
956 // against huge allocations when using vsnprintfT implementations that 956 // against huge allocations when using vsnprintfT implementations that
957 // return -1 for reasons other than overflow without setting errno. 957 // return -1 for reasons other than overflow without setting errno.
958 DLOG(WARNING) << "Unable to printf the requested string due to size."; 958 DLOG(WARNING) << "Unable to printf the requested string due to size.";
959 return; 959 return;
960 } 960 }
961 961
962 std::vector<typename StringType::value_type> mem_buf(mem_length); 962 std::vector<typename StringType::value_type> mem_buf(mem_length);
963 963
964 // Restore the va_list before we use it again. 964 // Restore the va_list before we use it again.
965 base::va_copy(backup_ap, ap); 965 GG_VA_COPY(backup_ap, ap);
966 966
967 result = vsnprintfT(&mem_buf[0], mem_length, format, ap); 967 result = vsnprintfT(&mem_buf[0], mem_length, format, ap);
968 va_end(backup_ap); 968 va_end(backup_ap);
969 969
970 if ((result >= 0) && (result < mem_length)) { 970 if ((result >= 0) && (result < mem_length)) {
971 // It fit. 971 // It fit.
972 dst->append(&mem_buf[0], result); 972 dst->append(&mem_buf[0], result);
973 return; 973 return;
974 } 974 }
975 } 975 }
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 // Each input byte creates two output hex characters. 1649 // Each input byte creates two output hex characters.
1650 std::string ret(size * 2, '\0'); 1650 std::string ret(size * 2, '\0');
1651 1651
1652 for (size_t i = 0; i < size; ++i) { 1652 for (size_t i = 0; i < size; ++i) {
1653 char b = reinterpret_cast<const char*>(bytes)[i]; 1653 char b = reinterpret_cast<const char*>(bytes)[i];
1654 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; 1654 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf];
1655 ret[(i * 2) + 1] = kHexChars[b & 0xf]; 1655 ret[(i * 2) + 1] = kHexChars[b & 0xf];
1656 } 1656 }
1657 return ret; 1657 return ret;
1658 } 1658 }
OLDNEW
« base/port.h ('K') | « base/port.h ('k') | base/string_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698