Migrate base::{size,empty,data} to STL equivalents in crashpad.

Bug: chromium:1299695
Change-Id: I95187a425b08c96430c659f843c379d506972f0f
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3496462
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Daniel Cheng 2022-02-28 20:57:19 -08:00 committed by Crashpad LUCI CQ
parent 2bb6f068a8
commit 0affe61689
106 changed files with 556 additions and 522 deletions

View File

@ -14,9 +14,9 @@
#include "client/crash_report_database.h" #include "client/crash_report_database.h"
#import <Foundation/Foundation.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#import <Foundation/Foundation.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -25,9 +25,9 @@
#include <unistd.h> #include <unistd.h>
#include <uuid/uuid.h> #include <uuid/uuid.h>
#include <iterator>
#include <tuple> #include <tuple>
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/scoped_nsautorelease_pool.h" #include "base/mac/scoped_nsautorelease_pool.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
@ -282,7 +282,7 @@ bool CrashReportDatabaseMac::Initialize(bool may_create) {
} }
// Create the three processing directories for the database. // Create the three processing directories for the database.
for (size_t i = 0; i < base::size(kReportDirectories); ++i) { for (size_t i = 0; i < std::size(kReportDirectories); ++i) {
if (!CreateOrEnsureDirectoryExists(base_dir_.Append(kReportDirectories[i]))) if (!CreateOrEnsureDirectoryExists(base_dir_.Append(kReportDirectories[i])))
return false; return false;
} }

View File

@ -17,8 +17,8 @@
#include <unistd.h> #include <unistd.h>
#include <ios> #include <ios>
#include <iterator>
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/mach_logging.h" #include "base/mac/mach_logging.h"
#include "base/mac/scoped_mach_port.h" #include "base/mac/scoped_mach_port.h"
@ -40,7 +40,7 @@ bool IsBeingDebugged() {
kinfo_proc kern_proc_info; kinfo_proc kern_proc_info;
int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()}; int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()};
size_t len = sizeof(kern_proc_info); size_t len = sizeof(kern_proc_info);
if (sysctl(mib, base::size(mib), &kern_proc_info, &len, nullptr, 0) == 0) if (sysctl(mib, std::size(mib), &kern_proc_info, &len, nullptr, 0) == 0)
return kern_proc_info.kp_proc.p_flag & P_TRACED; return kern_proc_info.kp_proc.p_flag & P_TRACED;
return false; return false;
} }
@ -111,7 +111,7 @@ class CrashHandler : public Thread,
mach_thread_self(), mach_thread_self(),
kSimulatedException, kSimulatedException,
code, code,
base::size(code), std::size(code),
MACHINE_THREAD_STATE, MACHINE_THREAD_STATE,
reinterpret_cast<ConstThreadState>(context), reinterpret_cast<ConstThreadState>(context),
MACHINE_THREAD_STATE_COUNT); MACHINE_THREAD_STATE_COUNT);
@ -304,7 +304,7 @@ class CrashHandler : public Thread,
mach_thread_self(), mach_thread_self(),
kMachExceptionFromNSException, kMachExceptionFromNSException,
code, code,
base::size(code), std::size(code),
MACHINE_THREAD_STATE, MACHINE_THREAD_STATE,
reinterpret_cast<ConstThreadState>(context), reinterpret_cast<ConstThreadState>(context),
MACHINE_THREAD_STATE_COUNT); MACHINE_THREAD_STATE_COUNT);

View File

@ -21,7 +21,8 @@
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <time.h> #include <time.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "build/build_config.h" #include "build/build_config.h"
#include "snapshot/snapshot_constants.h" #include "snapshot/snapshot_constants.h"
#include "util/ios/ios_intermediate_dump_writer.h" #include "util/ios/ios_intermediate_dump_writer.h"
@ -428,7 +429,7 @@ void CaptureMemoryPointedToByThreadState(IOSIntermediateDumpWriter* writer,
MaybeCaptureMemoryAround(writer, thread_state.__rip); MaybeCaptureMemoryAround(writer, thread_state.__rip);
#elif defined(ARCH_CPU_ARM_FAMILY) #elif defined(ARCH_CPU_ARM_FAMILY)
MaybeCaptureMemoryAround(writer, thread_state.__pc); MaybeCaptureMemoryAround(writer, thread_state.__pc);
for (size_t i = 0; i < base::size(thread_state.__x); ++i) { for (size_t i = 0; i < std::size(thread_state.__x); ++i) {
MaybeCaptureMemoryAround(writer, thread_state.__x[i]); MaybeCaptureMemoryAround(writer, thread_state.__x[i]);
} }
#endif #endif
@ -598,7 +599,7 @@ void InProcessIntermediateDumpHandler::WriteProcessInfo(
kinfo_proc kern_proc_info; kinfo_proc kern_proc_info;
int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()}; int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()};
size_t len = sizeof(kern_proc_info); size_t len = sizeof(kern_proc_info);
if (sysctl(mib, base::size(mib), &kern_proc_info, &len, nullptr, 0) == 0) { if (sysctl(mib, std::size(mib), &kern_proc_info, &len, nullptr, 0) == 0) {
WriteProperty( WriteProperty(
writer, IntermediateDumpKey::kPID, &kern_proc_info.kp_proc.p_pid); writer, IntermediateDumpKey::kPID, &kern_proc_info.kp_proc.p_pid);
WriteProperty(writer, WriteProperty(writer,

View File

@ -16,7 +16,8 @@
#include <sys/utsname.h> #include <sys/utsname.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "client/annotation.h" #include "client/annotation.h"
@ -74,7 +75,7 @@ class InProcessIntermediateDumpHandlerTest : public testing::Test {
mach_thread_self(), mach_thread_self(),
kSimulatedException, kSimulatedException,
code, code,
base::size(code), std::size(code),
MACHINE_THREAD_STATE, MACHINE_THREAD_STATE,
reinterpret_cast<ConstThreadState>(&cpu_context), reinterpret_cast<ConstThreadState>(&cpu_context),
MACHINE_THREAD_STATE_COUNT); MACHINE_THREAD_STATE_COUNT);

View File

@ -17,8 +17,9 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <iterator>
#include "base/check_op.h" #include "base/check_op.h"
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/mach_logging.h" #include "base/mac/mach_logging.h"
#include "base/mac/scoped_mach_port.h" #include "base/mac/scoped_mach_port.h"
@ -207,7 +208,7 @@ void SimulateCrash(const NativeCPUContext& cpu_context) {
base::mac::ScopedMachSendRight thread(mach_thread_self()); base::mac::ScopedMachSendRight thread(mach_thread_self());
exception_type_t exception = kMachExceptionSimulated; exception_type_t exception = kMachExceptionSimulated;
mach_exception_data_type_t codes[] = {0, 0}; mach_exception_data_type_t codes[] = {0, 0};
mach_msg_type_number_t code_count = base::size(codes); mach_msg_type_number_t code_count = std::size(codes);
// Look up the handler for EXC_CRASH exceptions in the same way that the // Look up the handler for EXC_CRASH exceptions in the same way that the
// kernel would: try a thread handler, then a task handler, and finally a host // kernel would: try a thread handler, then a task handler, and finally a host
@ -229,7 +230,7 @@ void SimulateCrash(const NativeCPUContext& cpu_context) {
bool success = false; bool success = false;
for (size_t target_type_index = 0; for (size_t target_type_index = 0;
!success && target_type_index < base::size(kTargetTypes); !success && target_type_index < std::size(kTargetTypes);
++target_type_index) { ++target_type_index) {
ExceptionPorts::ExceptionHandlerVector handlers; ExceptionPorts::ExceptionHandlerVector handlers;
ExceptionPorts exception_ports(kTargetTypes[target_type_index], ExceptionPorts exception_ports(kTargetTypes[target_type_index],

View File

@ -18,7 +18,8 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -370,13 +371,13 @@ TEST(SimulateCrash, SimulateCrash) {
#endif #endif
}; };
for (size_t target_index = 0; target_index < base::size(kTargets); for (size_t target_index = 0; target_index < std::size(kTargets);
++target_index) { ++target_index) {
TestSimulateCrashMac::ExceptionPortsTarget target = kTargets[target_index]; TestSimulateCrashMac::ExceptionPortsTarget target = kTargets[target_index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"target_index %zu, target %d", target_index, target)); "target_index %zu, target %d", target_index, target));
for (size_t behavior_index = 0; behavior_index < base::size(kBehaviors); for (size_t behavior_index = 0; behavior_index < std::size(kBehaviors);
++behavior_index) { ++behavior_index) {
exception_behavior_t behavior = kBehaviors[behavior_index]; exception_behavior_t behavior = kBehaviors[behavior_index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
@ -390,7 +391,7 @@ TEST(SimulateCrash, SimulateCrash) {
target, behavior, THREAD_STATE_NONE); target, behavior, THREAD_STATE_NONE);
test_simulate_crash_mac.Run(); test_simulate_crash_mac.Run();
} else { } else {
for (size_t flavor_index = 0; flavor_index < base::size(kFlavors); for (size_t flavor_index = 0; flavor_index < std::size(kFlavors);
++flavor_index) { ++flavor_index) {
thread_state_flavor_t flavor = kFlavors[flavor_index]; thread_state_flavor_t flavor = kFlavors[flavor_index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(

View File

@ -21,9 +21,9 @@
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <sys/types.h> #include <sys/types.h>
#include <iterator>
#include <string> #include <string>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "client/crashpad_info.h" #include "client/crashpad_info.h"
@ -108,7 +108,7 @@ void RecordFileLimitAnnotation() {
int mib[] = {CTL_KERN, KERN_MAXFILES}; int mib[] = {CTL_KERN, KERN_MAXFILES};
size = sizeof(value); size = sizeof(value);
std::string max_files = FormatFromSysctl( std::string max_files = FormatFromSysctl(
sysctl(mib, base::size(mib), &value, &size, nullptr, 0), &value, &size); sysctl(mib, std::size(mib), &value, &size, nullptr, 0), &value, &size);
std::string open_files = CountOpenFileDescriptors(); std::string open_files = CountOpenFileDescriptors();

View File

@ -19,12 +19,12 @@
#include <windows.h> #include <windows.h>
#include <winternl.h> #include <winternl.h>
#include <iterator>
#include <map> #include <map>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <vector> #include <vector>
#include "base/cxx17_backports.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h" #include "base/logging.h"
#include "build/build_config.h" #include "build/build_config.h"
@ -83,11 +83,11 @@ void AllocateMemoryOfVariousProtections() {
// All of these allocations are leaked, we want to view them in windbg via // All of these allocations are leaked, we want to view them in windbg via
// !vprot. // !vprot.
void* reserve = VirtualAlloc( void* reserve = VirtualAlloc(
nullptr, base::size(kPageTypes) * kPageSize, MEM_RESERVE, PAGE_READWRITE); nullptr, std::size(kPageTypes) * kPageSize, MEM_RESERVE, PAGE_READWRITE);
PCHECK(reserve) << "VirtualAlloc MEM_RESERVE"; PCHECK(reserve) << "VirtualAlloc MEM_RESERVE";
uintptr_t reserve_as_int = reinterpret_cast<uintptr_t>(reserve); uintptr_t reserve_as_int = reinterpret_cast<uintptr_t>(reserve);
for (size_t i = 0; i < base::size(kPageTypes); ++i) { for (size_t i = 0; i < std::size(kPageTypes); ++i) {
void* result = void* result =
VirtualAlloc(reinterpret_cast<void*>(reserve_as_int + (kPageSize * i)), VirtualAlloc(reinterpret_cast<void*>(reserve_as_int + (kPageSize * i)),
kPageSize, kPageSize,

View File

@ -15,7 +15,8 @@
#include <stdio.h> #include <stdio.h>
#include <windows.h> #include <windows.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/debug/alias.h" #include "base/debug/alias.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/notreached.h" #include "base/notreached.h"
@ -125,7 +126,7 @@ int wmain(int argc, wchar_t* argv[]) {
// This is not expected to return. // This is not expected to return.
DWORD count = WaitForMultipleObjects( DWORD count = WaitForMultipleObjects(
static_cast<DWORD>(base::size(threads)), threads, true, INFINITE); static_cast<DWORD>(std::size(threads)), threads, true, INFINITE);
if (count == WAIT_FAILED) { if (count == WAIT_FAILED) {
PLOG(ERROR) << "WaitForMultipleObjects"; PLOG(ERROR) << "WaitForMultipleObjects";
} else { } else {

View File

@ -14,9 +14,9 @@
#include "minidump/minidump_annotation_writer.h" #include "minidump/minidump_annotation_writer.h"
#include <iterator>
#include <memory> #include <memory>
#include "base/cxx17_backports.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "minidump/minidump_extensions.h" #include "minidump/minidump_extensions.h"
#include "minidump/test/minidump_byte_array_writer_test_util.h" #include "minidump/test/minidump_byte_array_writer_test_util.h"
@ -107,7 +107,7 @@ TEST(MinidumpAnnotationWriter, ThreeItems) {
MinidumpAnnotationListWriter list_writer; MinidumpAnnotationListWriter list_writer;
for (size_t i = 0; i < base::size(kNames); ++i) { for (size_t i = 0; i < std::size(kNames); ++i) {
auto annotation = std::make_unique<MinidumpAnnotationWriter>(); auto annotation = std::make_unique<MinidumpAnnotationWriter>();
annotation->InitializeWithData(kNames[i], kTypes[i], kValues[i]); annotation->InitializeWithData(kNames[i], kTypes[i], kValues[i]);
list_writer.AddObject(std::move(annotation)); list_writer.AddObject(std::move(annotation));

View File

@ -14,9 +14,9 @@
#include "minidump/minidump_byte_array_writer.h" #include "minidump/minidump_byte_array_writer.h"
#include <iterator>
#include <memory> #include <memory>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -35,7 +35,7 @@ TEST(MinidumpByteArrayWriter, Write) {
{}, {},
}; };
for (size_t i = 0; i < base::size(kTests); ++i) { for (size_t i = 0; i < std::size(kTests); ++i) {
SCOPED_TRACE(base::StringPrintf("index %" PRIuS, i)); SCOPED_TRACE(base::StringPrintf("index %" PRIuS, i));
StringFile string_file; StringFile string_file;
@ -67,7 +67,7 @@ TEST(MinidumpByteArrayWriter, SetData) {
{}, {},
}; };
for (size_t i = 0; i < base::size(kTests); ++i) { for (size_t i = 0; i < std::size(kTests); ++i) {
SCOPED_TRACE(base::StringPrintf("index %" PRIuS, i)); SCOPED_TRACE(base::StringPrintf("index %" PRIuS, i));
crashpad::MinidumpByteArrayWriter writer; crashpad::MinidumpByteArrayWriter writer;

View File

@ -14,10 +14,10 @@
#include "minidump/minidump_exception_writer.h" #include "minidump/minidump_exception_writer.h"
#include <iterator>
#include <string> #include <string>
#include <utility> #include <utility>
#include "base/cxx17_backports.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "minidump/minidump_context.h" #include "minidump/minidump_context.h"
#include "minidump/minidump_context_writer.h" #include "minidump/minidump_context_writer.h"
@ -86,7 +86,7 @@ void ExpectExceptionStream(const MINIDUMP_EXCEPTION_STREAM* expected,
expected_exception.NumberParameters); expected_exception.NumberParameters);
EXPECT_EQ(observed->ExceptionRecord.__unusedAlignment, 0u); EXPECT_EQ(observed->ExceptionRecord.__unusedAlignment, 0u);
for (size_t index = 0; for (size_t index = 0;
index < base::size(observed_exception.ExceptionInformation); index < std::size(observed_exception.ExceptionInformation);
++index) { ++index) {
EXPECT_EQ(observed_exception.ExceptionInformation[index], EXPECT_EQ(observed_exception.ExceptionInformation[index],
expected_exception.ExceptionInformation[index]); expected_exception.ExceptionInformation[index]);

View File

@ -17,10 +17,10 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <iterator>
#include <string> #include <string>
#include <utility> #include <utility>
#include "base/cxx17_backports.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "minidump/minidump_stream_writer.h" #include "minidump/minidump_stream_writer.h"
@ -156,7 +156,7 @@ TEST(MinidumpFileWriter, AddUserExtensionStream) {
minidump_file.SetTimestamp(kTimestamp); minidump_file.SetTimestamp(kTimestamp);
static constexpr uint8_t kStreamData[] = "Hello World!"; static constexpr uint8_t kStreamData[] = "Hello World!";
constexpr size_t kStreamSize = base::size(kStreamData); constexpr size_t kStreamSize = std::size(kStreamData);
constexpr MinidumpStreamType kStreamType = constexpr MinidumpStreamType kStreamType =
static_cast<MinidumpStreamType>(0x4d); static_cast<MinidumpStreamType>(0x4d);

View File

@ -14,9 +14,9 @@
#include "minidump/minidump_memory_writer.h" #include "minidump/minidump_memory_writer.h"
#include <iterator>
#include <utility> #include <utility>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -342,7 +342,7 @@ TEST(MinidumpMemoryWriter, ExtraMemory) {
TEST(MinidumpMemoryWriter, AddFromSnapshot) { TEST(MinidumpMemoryWriter, AddFromSnapshot) {
MINIDUMP_MEMORY_DESCRIPTOR expect_memory_descriptors[3] = {}; MINIDUMP_MEMORY_DESCRIPTOR expect_memory_descriptors[3] = {};
uint8_t values[base::size(expect_memory_descriptors)] = {}; uint8_t values[std::size(expect_memory_descriptors)] = {};
expect_memory_descriptors[0].StartOfMemoryRange = 0; expect_memory_descriptors[0].StartOfMemoryRange = 0;
expect_memory_descriptors[0].Memory.DataSize = 0x1000; expect_memory_descriptors[0].Memory.DataSize = 0x1000;
@ -358,7 +358,7 @@ TEST(MinidumpMemoryWriter, AddFromSnapshot) {
std::vector<std::unique_ptr<TestMemorySnapshot>> memory_snapshots_owner; std::vector<std::unique_ptr<TestMemorySnapshot>> memory_snapshots_owner;
std::vector<const MemorySnapshot*> memory_snapshots; std::vector<const MemorySnapshot*> memory_snapshots;
for (size_t index = 0; index < base::size(expect_memory_descriptors); for (size_t index = 0; index < std::size(expect_memory_descriptors);
++index) { ++index) {
memory_snapshots_owner.push_back(std::make_unique<TestMemorySnapshot>()); memory_snapshots_owner.push_back(std::make_unique<TestMemorySnapshot>());
TestMemorySnapshot* memory_snapshot = memory_snapshots_owner.back().get(); TestMemorySnapshot* memory_snapshot = memory_snapshots_owner.back().get();
@ -397,7 +397,7 @@ TEST(MinidumpMemoryWriter, AddFromSnapshot) {
TEST(MinidumpMemoryWriter, CoalesceExplicitMultiple) { TEST(MinidumpMemoryWriter, CoalesceExplicitMultiple) {
MINIDUMP_MEMORY_DESCRIPTOR expect_memory_descriptors[4] = {}; MINIDUMP_MEMORY_DESCRIPTOR expect_memory_descriptors[4] = {};
uint8_t values[base::size(expect_memory_descriptors)] = {}; uint8_t values[std::size(expect_memory_descriptors)] = {};
expect_memory_descriptors[0].StartOfMemoryRange = 0; expect_memory_descriptors[0].StartOfMemoryRange = 0;
expect_memory_descriptors[0].Memory.DataSize = 1000; expect_memory_descriptors[0].Memory.DataSize = 1000;

View File

@ -14,10 +14,10 @@
#include "minidump/minidump_misc_info_writer.h" #include "minidump/minidump_misc_info_writer.h"
#include <iterator>
#include <limits> #include <limits>
#include "base/check_op.h" #include "base/check_op.h"
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
@ -311,7 +311,7 @@ void MinidumpMiscInfoWriter::SetTimeZone(uint32_t time_zone_id,
internal::MinidumpWriterUtil::AssignUTF8ToUTF16( internal::MinidumpWriterUtil::AssignUTF8ToUTF16(
AsU16CStr(misc_info_.TimeZone.StandardName), AsU16CStr(misc_info_.TimeZone.StandardName),
base::size(misc_info_.TimeZone.StandardName), std::size(misc_info_.TimeZone.StandardName),
standard_name); standard_name);
misc_info_.TimeZone.StandardDate = standard_date; misc_info_.TimeZone.StandardDate = standard_date;
@ -319,7 +319,7 @@ void MinidumpMiscInfoWriter::SetTimeZone(uint32_t time_zone_id,
internal::MinidumpWriterUtil::AssignUTF8ToUTF16( internal::MinidumpWriterUtil::AssignUTF8ToUTF16(
AsU16CStr(misc_info_.TimeZone.DaylightName), AsU16CStr(misc_info_.TimeZone.DaylightName),
base::size(misc_info_.TimeZone.DaylightName), std::size(misc_info_.TimeZone.DaylightName),
daylight_name); daylight_name);
misc_info_.TimeZone.DaylightDate = daylight_date; misc_info_.TimeZone.DaylightDate = daylight_date;
@ -337,11 +337,11 @@ void MinidumpMiscInfoWriter::SetBuildString(
internal::MinidumpWriterUtil::AssignUTF8ToUTF16( internal::MinidumpWriterUtil::AssignUTF8ToUTF16(
AsU16CStr(misc_info_.BuildString), AsU16CStr(misc_info_.BuildString),
base::size(misc_info_.BuildString), std::size(misc_info_.BuildString),
build_string); build_string);
internal::MinidumpWriterUtil::AssignUTF8ToUTF16( internal::MinidumpWriterUtil::AssignUTF8ToUTF16(
AsU16CStr(misc_info_.DbgBldStr), AsU16CStr(misc_info_.DbgBldStr),
base::size(misc_info_.DbgBldStr), std::size(misc_info_.DbgBldStr),
debug_build_string); debug_build_string);
} }

View File

@ -16,10 +16,10 @@
#include <string.h> #include <string.h>
#include <iterator>
#include <string> #include <string>
#include <utility> #include <utility>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
@ -125,7 +125,7 @@ void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_3>(
SCOPED_TRACE("Standard"); SCOPED_TRACE("Standard");
ExpectNULPaddedString16Equal(AsU16CStr(expected->TimeZone.StandardName), ExpectNULPaddedString16Equal(AsU16CStr(expected->TimeZone.StandardName),
AsU16CStr(observed->TimeZone.StandardName), AsU16CStr(observed->TimeZone.StandardName),
base::size(expected->TimeZone.StandardName)); std::size(expected->TimeZone.StandardName));
ExpectSystemTimeEqual(&expected->TimeZone.StandardDate, ExpectSystemTimeEqual(&expected->TimeZone.StandardDate,
&observed->TimeZone.StandardDate); &observed->TimeZone.StandardDate);
EXPECT_EQ(observed->TimeZone.StandardBias, expected->TimeZone.StandardBias); EXPECT_EQ(observed->TimeZone.StandardBias, expected->TimeZone.StandardBias);
@ -134,7 +134,7 @@ void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_3>(
SCOPED_TRACE("Daylight"); SCOPED_TRACE("Daylight");
ExpectNULPaddedString16Equal(AsU16CStr(expected->TimeZone.DaylightName), ExpectNULPaddedString16Equal(AsU16CStr(expected->TimeZone.DaylightName),
AsU16CStr(observed->TimeZone.DaylightName), AsU16CStr(observed->TimeZone.DaylightName),
base::size(expected->TimeZone.DaylightName)); std::size(expected->TimeZone.DaylightName));
ExpectSystemTimeEqual(&expected->TimeZone.DaylightDate, ExpectSystemTimeEqual(&expected->TimeZone.DaylightDate,
&observed->TimeZone.DaylightDate); &observed->TimeZone.DaylightDate);
EXPECT_EQ(observed->TimeZone.DaylightBias, expected->TimeZone.DaylightBias); EXPECT_EQ(observed->TimeZone.DaylightBias, expected->TimeZone.DaylightBias);
@ -152,13 +152,13 @@ void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_4>(
SCOPED_TRACE("BuildString"); SCOPED_TRACE("BuildString");
ExpectNULPaddedString16Equal(AsU16CStr(expected->BuildString), ExpectNULPaddedString16Equal(AsU16CStr(expected->BuildString),
AsU16CStr(observed->BuildString), AsU16CStr(observed->BuildString),
base::size(expected->BuildString)); std::size(expected->BuildString));
} }
{ {
SCOPED_TRACE("DbgBldStr"); SCOPED_TRACE("DbgBldStr");
ExpectNULPaddedString16Equal(AsU16CStr(expected->DbgBldStr), ExpectNULPaddedString16Equal(AsU16CStr(expected->DbgBldStr),
AsU16CStr(observed->DbgBldStr), AsU16CStr(observed->DbgBldStr),
base::size(expected->DbgBldStr)); std::size(expected->DbgBldStr));
} }
} }
@ -181,7 +181,7 @@ void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_5>(
EXPECT_EQ(observed_misc_info.XStateData.EnabledFeatures, EXPECT_EQ(observed_misc_info.XStateData.EnabledFeatures,
expected_misc_info.XStateData.EnabledFeatures); expected_misc_info.XStateData.EnabledFeatures);
for (size_t feature_index = 0; for (size_t feature_index = 0;
feature_index < base::size(observed_misc_info.XStateData.Features); feature_index < std::size(observed_misc_info.XStateData.Features);
++feature_index) { ++feature_index) {
SCOPED_TRACE(base::StringPrintf("feature_index %" PRIuS, feature_index)); SCOPED_TRACE(base::StringPrintf("feature_index %" PRIuS, feature_index));
EXPECT_EQ(observed_misc_info.XStateData.Features[feature_index].Offset, EXPECT_EQ(observed_misc_info.XStateData.Features[feature_index].Offset,
@ -408,7 +408,7 @@ TEST(MinidumpMiscInfoWriter, TimeZone) {
base::UTF8ToUTF16(Crbug1189439Cast(kStandardName)); base::UTF8ToUTF16(Crbug1189439Cast(kStandardName));
c16lcpy(AsU16CStr(expected.TimeZone.StandardName), c16lcpy(AsU16CStr(expected.TimeZone.StandardName),
standard_name_utf16.c_str(), standard_name_utf16.c_str(),
base::size(expected.TimeZone.StandardName)); std::size(expected.TimeZone.StandardName));
memcpy(&expected.TimeZone.StandardDate, memcpy(&expected.TimeZone.StandardDate,
&kStandardDate, &kStandardDate,
sizeof(expected.TimeZone.StandardDate)); sizeof(expected.TimeZone.StandardDate));
@ -417,7 +417,7 @@ TEST(MinidumpMiscInfoWriter, TimeZone) {
base::UTF8ToUTF16(Crbug1189439Cast(kDaylightName)); base::UTF8ToUTF16(Crbug1189439Cast(kDaylightName));
c16lcpy(AsU16CStr(expected.TimeZone.DaylightName), c16lcpy(AsU16CStr(expected.TimeZone.DaylightName),
daylight_name_utf16.c_str(), daylight_name_utf16.c_str(),
base::size(expected.TimeZone.DaylightName)); std::size(expected.TimeZone.DaylightName));
memcpy(&expected.TimeZone.DaylightDate, memcpy(&expected.TimeZone.DaylightDate,
&kDaylightDate, &kDaylightDate,
sizeof(expected.TimeZone.DaylightDate)); sizeof(expected.TimeZone.DaylightDate));
@ -436,9 +436,9 @@ TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) {
constexpr uint32_t kTimeZoneId = 2; constexpr uint32_t kTimeZoneId = 2;
constexpr int32_t kBias = 300; constexpr int32_t kBias = 300;
[[maybe_unused]] MINIDUMP_MISC_INFO_N tmp; [[maybe_unused]] MINIDUMP_MISC_INFO_N tmp;
std::string standard_name(base::size(tmp.TimeZone.StandardName) + 1, 's'); std::string standard_name(std::size(tmp.TimeZone.StandardName) + 1, 's');
constexpr int32_t kStandardBias = 0; constexpr int32_t kStandardBias = 0;
std::string daylight_name(base::size(tmp.TimeZone.DaylightName), 'd'); std::string daylight_name(std::size(tmp.TimeZone.DaylightName), 'd');
constexpr int32_t kDaylightBias = -60; constexpr int32_t kDaylightBias = -60;
// Test using kSystemTimeZero, because not all platforms will be able to // Test using kSystemTimeZero, because not all platforms will be able to
@ -469,7 +469,7 @@ TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) {
std::u16string standard_name_utf16 = base::UTF8ToUTF16(standard_name); std::u16string standard_name_utf16 = base::UTF8ToUTF16(standard_name);
c16lcpy(AsU16CStr(expected.TimeZone.StandardName), c16lcpy(AsU16CStr(expected.TimeZone.StandardName),
standard_name_utf16.c_str(), standard_name_utf16.c_str(),
base::size(expected.TimeZone.StandardName)); std::size(expected.TimeZone.StandardName));
memcpy(&expected.TimeZone.StandardDate, memcpy(&expected.TimeZone.StandardDate,
&kSystemTimeZero, &kSystemTimeZero,
sizeof(expected.TimeZone.StandardDate)); sizeof(expected.TimeZone.StandardDate));
@ -477,7 +477,7 @@ TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) {
std::u16string daylight_name_utf16 = base::UTF8ToUTF16(daylight_name); std::u16string daylight_name_utf16 = base::UTF8ToUTF16(daylight_name);
c16lcpy(AsU16CStr(expected.TimeZone.DaylightName), c16lcpy(AsU16CStr(expected.TimeZone.DaylightName),
daylight_name_utf16.c_str(), daylight_name_utf16.c_str(),
base::size(expected.TimeZone.DaylightName)); std::size(expected.TimeZone.DaylightName));
memcpy(&expected.TimeZone.DaylightDate, memcpy(&expected.TimeZone.DaylightDate,
&kSystemTimeZero, &kSystemTimeZero,
sizeof(expected.TimeZone.DaylightDate)); sizeof(expected.TimeZone.DaylightDate));
@ -509,12 +509,12 @@ TEST(MinidumpMiscInfoWriter, BuildStrings) {
base::UTF8ToUTF16(Crbug1189439Cast(kBuildString)); base::UTF8ToUTF16(Crbug1189439Cast(kBuildString));
c16lcpy(AsU16CStr(expected.BuildString), c16lcpy(AsU16CStr(expected.BuildString),
build_string_utf16.c_str(), build_string_utf16.c_str(),
base::size(expected.BuildString)); std::size(expected.BuildString));
std::u16string debug_build_string_utf16 = std::u16string debug_build_string_utf16 =
base::UTF8ToUTF16(Crbug1189439Cast(kDebugBuildString)); base::UTF8ToUTF16(Crbug1189439Cast(kDebugBuildString));
c16lcpy(AsU16CStr(expected.DbgBldStr), c16lcpy(AsU16CStr(expected.DbgBldStr),
debug_build_string_utf16.c_str(), debug_build_string_utf16.c_str(),
base::size(expected.DbgBldStr)); std::size(expected.DbgBldStr));
ExpectMiscInfoEqual(&expected, observed); ExpectMiscInfoEqual(&expected, observed);
} }
@ -527,8 +527,8 @@ TEST(MinidumpMiscInfoWriter, BuildStringsOverflow) {
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>(); auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
[[maybe_unused]] MINIDUMP_MISC_INFO_N tmp; [[maybe_unused]] MINIDUMP_MISC_INFO_N tmp;
std::string build_string(base::size(tmp.BuildString) + 1, 'B'); std::string build_string(std::size(tmp.BuildString) + 1, 'B');
std::string debug_build_string(base::size(tmp.DbgBldStr), 'D'); std::string debug_build_string(std::size(tmp.DbgBldStr), 'D');
misc_info_writer->SetBuildString(build_string, debug_build_string); misc_info_writer->SetBuildString(build_string, debug_build_string);
@ -545,12 +545,12 @@ TEST(MinidumpMiscInfoWriter, BuildStringsOverflow) {
std::u16string build_string_utf16 = base::UTF8ToUTF16(build_string); std::u16string build_string_utf16 = base::UTF8ToUTF16(build_string);
c16lcpy(AsU16CStr(expected.BuildString), c16lcpy(AsU16CStr(expected.BuildString),
build_string_utf16.c_str(), build_string_utf16.c_str(),
base::size(expected.BuildString)); std::size(expected.BuildString));
std::u16string debug_build_string_utf16 = std::u16string debug_build_string_utf16 =
base::UTF8ToUTF16(debug_build_string); base::UTF8ToUTF16(debug_build_string);
c16lcpy(AsU16CStr(expected.DbgBldStr), c16lcpy(AsU16CStr(expected.DbgBldStr),
debug_build_string_utf16.c_str(), debug_build_string_utf16.c_str(),
base::size(expected.DbgBldStr)); std::size(expected.DbgBldStr));
ExpectMiscInfoEqual(&expected, observed); ExpectMiscInfoEqual(&expected, observed);
} }
@ -691,7 +691,7 @@ TEST(MinidumpMiscInfoWriter, Everything) {
base::UTF8ToUTF16(Crbug1189439Cast(kStandardName)); base::UTF8ToUTF16(Crbug1189439Cast(kStandardName));
c16lcpy(AsU16CStr(expected.TimeZone.StandardName), c16lcpy(AsU16CStr(expected.TimeZone.StandardName),
standard_name_utf16.c_str(), standard_name_utf16.c_str(),
base::size(expected.TimeZone.StandardName)); std::size(expected.TimeZone.StandardName));
memcpy(&expected.TimeZone.StandardDate, memcpy(&expected.TimeZone.StandardDate,
&kSystemTimeZero, &kSystemTimeZero,
sizeof(expected.TimeZone.StandardDate)); sizeof(expected.TimeZone.StandardDate));
@ -700,7 +700,7 @@ TEST(MinidumpMiscInfoWriter, Everything) {
base::UTF8ToUTF16(Crbug1189439Cast(kDaylightName)); base::UTF8ToUTF16(Crbug1189439Cast(kDaylightName));
c16lcpy(AsU16CStr(expected.TimeZone.DaylightName), c16lcpy(AsU16CStr(expected.TimeZone.DaylightName),
daylight_name_utf16.c_str(), daylight_name_utf16.c_str(),
base::size(expected.TimeZone.DaylightName)); std::size(expected.TimeZone.DaylightName));
memcpy(&expected.TimeZone.DaylightDate, memcpy(&expected.TimeZone.DaylightDate,
&kSystemTimeZero, &kSystemTimeZero,
sizeof(expected.TimeZone.DaylightDate)); sizeof(expected.TimeZone.DaylightDate));
@ -709,12 +709,12 @@ TEST(MinidumpMiscInfoWriter, Everything) {
base::UTF8ToUTF16(Crbug1189439Cast(kBuildString)); base::UTF8ToUTF16(Crbug1189439Cast(kBuildString));
c16lcpy(AsU16CStr(expected.BuildString), c16lcpy(AsU16CStr(expected.BuildString),
build_string_utf16.c_str(), build_string_utf16.c_str(),
base::size(expected.BuildString)); std::size(expected.BuildString));
std::u16string debug_build_string_utf16 = std::u16string debug_build_string_utf16 =
base::UTF8ToUTF16(Crbug1189439Cast(kDebugBuildString)); base::UTF8ToUTF16(Crbug1189439Cast(kDebugBuildString));
c16lcpy(AsU16CStr(expected.DbgBldStr), c16lcpy(AsU16CStr(expected.DbgBldStr),
debug_build_string_utf16.c_str(), debug_build_string_utf16.c_str(),
base::size(expected.DbgBldStr)); std::size(expected.DbgBldStr));
ExpectMiscInfoEqual(&expected, observed); ExpectMiscInfoEqual(&expected, observed);
} }
@ -758,18 +758,18 @@ TEST(MinidumpMiscInfoWriter, InitializeFromSnapshot) {
expect_misc_info.TimeZone.Bias = 300; expect_misc_info.TimeZone.Bias = 300;
c16lcpy(AsU16CStr(expect_misc_info.TimeZone.StandardName), c16lcpy(AsU16CStr(expect_misc_info.TimeZone.StandardName),
standard_time_name_utf16.c_str(), standard_time_name_utf16.c_str(),
base::size(expect_misc_info.TimeZone.StandardName)); std::size(expect_misc_info.TimeZone.StandardName));
expect_misc_info.TimeZone.StandardBias = 0; expect_misc_info.TimeZone.StandardBias = 0;
c16lcpy(AsU16CStr(expect_misc_info.TimeZone.DaylightName), c16lcpy(AsU16CStr(expect_misc_info.TimeZone.DaylightName),
daylight_time_name_utf16.c_str(), daylight_time_name_utf16.c_str(),
base::size(expect_misc_info.TimeZone.DaylightName)); std::size(expect_misc_info.TimeZone.DaylightName));
expect_misc_info.TimeZone.DaylightBias = -60; expect_misc_info.TimeZone.DaylightBias = -60;
c16lcpy(AsU16CStr(expect_misc_info.BuildString), c16lcpy(AsU16CStr(expect_misc_info.BuildString),
build_string_utf16.c_str(), build_string_utf16.c_str(),
base::size(expect_misc_info.BuildString)); std::size(expect_misc_info.BuildString));
c16lcpy(AsU16CStr(expect_misc_info.DbgBldStr), c16lcpy(AsU16CStr(expect_misc_info.DbgBldStr),
debug_build_string_utf16.c_str(), debug_build_string_utf16.c_str(),
base::size(expect_misc_info.DbgBldStr)); std::size(expect_misc_info.DbgBldStr));
const timeval kStartTime = { const timeval kStartTime = {
static_cast<long>(expect_misc_info.ProcessCreateTime), 0}; static_cast<long>(expect_misc_info.ProcessCreateTime), 0};

View File

@ -17,9 +17,9 @@
#include <windows.h> #include <windows.h>
#include <dbghelp.h> #include <dbghelp.h>
#include <iterator>
#include <utility> #include <utility>
#include "base/cxx17_backports.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "minidump/minidump_annotation_writer.h" #include "minidump/minidump_annotation_writer.h"
#include "minidump/minidump_simple_string_dictionary_writer.h" #include "minidump/minidump_simple_string_dictionary_writer.h"
@ -155,9 +155,9 @@ TEST(MinidumpModuleCrashpadInfoWriter, FullModule) {
sizeof(MinidumpSimpleStringDictionaryEntry) + sizeof(MinidumpSimpleStringDictionaryEntry) +
sizeof(MinidumpAnnotationList) + 2 + // padding sizeof(MinidumpAnnotationList) + 2 + // padding
sizeof(MinidumpAnnotation) + sizeof(MinidumpUTF8String) + sizeof(MinidumpAnnotation) + sizeof(MinidumpUTF8String) +
base::size(kEntry) + 2 + // padding std::size(kEntry) + 2 + // padding
sizeof(MinidumpUTF8String) + base::size(kKey) + sizeof(MinidumpUTF8String) + std::size(kKey) +
sizeof(MinidumpUTF8String) + base::size(kValue) + sizeof(MinidumpUTF8String) + std::size(kValue) +
sizeof(MinidumpUTF8String) + annotation.name.size() + 1 + sizeof(MinidumpUTF8String) + annotation.name.size() + 1 +
sizeof(MinidumpByteArray) + annotation.value.size()); sizeof(MinidumpByteArray) + annotation.value.size());

View File

@ -17,9 +17,9 @@
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <iterator>
#include <utility> #include <utility>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
@ -793,10 +793,10 @@ void InitializeTestModuleSnapshotFromMinidumpModule(
TEST(MinidumpModuleWriter, InitializeFromSnapshot) { TEST(MinidumpModuleWriter, InitializeFromSnapshot) {
MINIDUMP_MODULE expect_modules[3] = {}; MINIDUMP_MODULE expect_modules[3] = {};
const char* module_paths[base::size(expect_modules)] = {}; const char* module_paths[std::size(expect_modules)] = {};
const char* module_pdbs[base::size(expect_modules)] = {}; const char* module_pdbs[std::size(expect_modules)] = {};
UUID uuids[base::size(expect_modules)] = {}; UUID uuids[std::size(expect_modules)] = {};
uint32_t ages[base::size(expect_modules)] = {}; uint32_t ages[std::size(expect_modules)] = {};
expect_modules[0].BaseOfImage = 0x100101000; expect_modules[0].BaseOfImage = 0x100101000;
expect_modules[0].SizeOfImage = 0xf000; expect_modules[0].SizeOfImage = 0xf000;
@ -887,7 +887,7 @@ TEST(MinidumpModuleWriter, InitializeFromSnapshot) {
std::vector<std::unique_ptr<TestModuleSnapshot>> module_snapshots_owner; std::vector<std::unique_ptr<TestModuleSnapshot>> module_snapshots_owner;
std::vector<const ModuleSnapshot*> module_snapshots; std::vector<const ModuleSnapshot*> module_snapshots;
for (size_t index = 0; index < base::size(expect_modules); ++index) { for (size_t index = 0; index < std::size(expect_modules); ++index) {
module_snapshots_owner.push_back(std::make_unique<TestModuleSnapshot>()); module_snapshots_owner.push_back(std::make_unique<TestModuleSnapshot>());
TestModuleSnapshot* module_snapshot = module_snapshots_owner.back().get(); TestModuleSnapshot* module_snapshot = module_snapshots_owner.back().get();
InitializeTestModuleSnapshotFromMinidumpModule(module_snapshot, InitializeTestModuleSnapshotFromMinidumpModule(module_snapshot,

View File

@ -14,9 +14,9 @@
#include "minidump/minidump_rva_list_writer.h" #include "minidump/minidump_rva_list_writer.h"
#include <iterator>
#include <utility> #include <utility>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -89,10 +89,10 @@ TEST(MinidumpRVAListWriter, ThreeChildren) {
ASSERT_TRUE(list_writer.WriteEverything(&string_file)); ASSERT_TRUE(list_writer.WriteEverything(&string_file));
const MinidumpRVAList* list = const MinidumpRVAList* list =
MinidumpRVAListAtStart(string_file.string(), base::size(kValues)); MinidumpRVAListAtStart(string_file.string(), std::size(kValues));
ASSERT_TRUE(list); ASSERT_TRUE(list);
for (size_t index = 0; index < base::size(kValues); ++index) { for (size_t index = 0; index < std::size(kValues); ++index) {
SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index)); SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index));
const uint32_t* child = MinidumpWritableAtRVA<uint32_t>( const uint32_t* child = MinidumpWritableAtRVA<uint32_t>(

View File

@ -14,9 +14,9 @@
#include "minidump/minidump_string_writer.h" #include "minidump/minidump_string_writer.h"
#include <iterator>
#include <string> #include <string>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
@ -66,15 +66,14 @@ TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) {
{4, "\360\220\204\202", 2, {0xd800, 0xdd02}}, // 𐄂 (non-BMP) {4, "\360\220\204\202", 2, {0xd800, 0xdd02}}, // 𐄂 (non-BMP)
}; };
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %" PRIuS ", input %s", index, kTestData[index].input_string)); "index %" PRIuS ", input %s", index, kTestData[index].input_string));
// Make sure that the expected output string with its NUL terminator fits in // Make sure that the expected output string with its NUL terminator fits in
// the space provided. // the space provided.
ASSERT_EQ( ASSERT_EQ(kTestData[index]
kTestData[index] .output_string[std::size(kTestData[index].output_string) - 1],
.output_string[base::size(kTestData[index].output_string) - 1],
0); 0);
string_file.Reset(); string_file.Reset();
@ -112,7 +111,7 @@ TEST(MinidumpStringWriter, ConvertInvalidUTF8ToUTF16) {
"\303\0\251", // NUL in middle of valid sequence "\303\0\251", // NUL in middle of valid sequence
}; };
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %" PRIuS ", input %s", index, kTestData[index])); "index %" PRIuS ", input %s", index, kTestData[index]));
string_file.Reset(); string_file.Reset();
@ -173,7 +172,7 @@ TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) {
{4, "\360\220\204\202"}, // 𐄂 (non-BMP) {4, "\360\220\204\202"}, // 𐄂 (non-BMP)
}; };
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %" PRIuS ", input %s", index, kTestData[index].string)); "index %" PRIuS ", input %s", index, kTestData[index].string));

View File

@ -16,8 +16,9 @@
#include <string.h> #include <string.h>
#include <iterator>
#include "base/check_op.h" #include "base/check_op.h"
#include "base/cxx17_backports.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "minidump/minidump_string_writer.h" #include "minidump/minidump_string_writer.h"
#include "snapshot/system_snapshot.h" #include "snapshot/system_snapshot.h"
@ -235,7 +236,7 @@ void MinidumpSystemInfoWriter::SetCPUX86VendorString(
sizeof(registers) == sizeof(system_info_.Cpu.X86CpuInfo.VendorId), sizeof(registers) == sizeof(system_info_.Cpu.X86CpuInfo.VendorId),
"VendorId sizes must be equal"); "VendorId sizes must be equal");
for (size_t index = 0; index < base::size(registers); ++index) { for (size_t index = 0; index < std::size(registers); ++index) {
memcpy(&registers[index], memcpy(&registers[index],
&vendor[index * sizeof(*registers)], &vendor[index * sizeof(*registers)],
sizeof(*registers)); sizeof(*registers));

View File

@ -16,9 +16,9 @@
#include <sys/types.h> #include <sys/types.h>
#include <iterator>
#include <vector> #include <vector>
#include "base/cxx17_backports.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "snapshot/test/test_thread_snapshot.h" #include "snapshot/test/test_thread_snapshot.h"
@ -41,8 +41,7 @@ class MinidumpThreadIDMapTest : public testing::Test {
// testing::Test: // testing::Test:
void SetUp() override { void SetUp() override {
for (size_t index = 0; index < base::size(test_thread_snapshots_); for (size_t index = 0; index < std::size(test_thread_snapshots_); ++index) {
++index) {
thread_snapshots_.push_back(&test_thread_snapshots_[index]); thread_snapshots_.push_back(&test_thread_snapshots_[index]);
} }
} }
@ -63,7 +62,7 @@ class MinidumpThreadIDMapTest : public testing::Test {
} }
void SetThreadID(size_t index, uint64_t thread_id) { void SetThreadID(size_t index, uint64_t thread_id) {
ASSERT_LT(index, base::size(test_thread_snapshots_)); ASSERT_LT(index, std::size(test_thread_snapshots_));
test_thread_snapshots_[index].SetThreadID(thread_id); test_thread_snapshots_[index].SetThreadID(thread_id);
} }

View File

@ -14,11 +14,11 @@
#include "minidump/minidump_thread_writer.h" #include "minidump/minidump_thread_writer.h"
#include <iterator>
#include <string> #include <string>
#include <utility> #include <utility>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -531,10 +531,10 @@ template <typename Traits>
void RunInitializeFromSnapshotTest(bool thread_id_collision) { void RunInitializeFromSnapshotTest(bool thread_id_collision) {
using MinidumpContextType = typename Traits::MinidumpContextType; using MinidumpContextType = typename Traits::MinidumpContextType;
MINIDUMP_THREAD expect_threads[3] = {}; MINIDUMP_THREAD expect_threads[3] = {};
uint64_t thread_ids[base::size(expect_threads)] = {}; uint64_t thread_ids[std::size(expect_threads)] = {};
uint8_t memory_values[base::size(expect_threads)] = {}; uint8_t memory_values[std::size(expect_threads)] = {};
uint32_t context_seeds[base::size(expect_threads)] = {}; uint32_t context_seeds[std::size(expect_threads)] = {};
MINIDUMP_MEMORY_DESCRIPTOR tebs[base::size(expect_threads)] = {}; MINIDUMP_MEMORY_DESCRIPTOR tebs[std::size(expect_threads)] = {};
constexpr size_t kTebSize = 1024; constexpr size_t kTebSize = 1024;
@ -590,7 +590,7 @@ void RunInitializeFromSnapshotTest(bool thread_id_collision) {
std::vector<std::unique_ptr<TestThreadSnapshot>> thread_snapshots_owner; std::vector<std::unique_ptr<TestThreadSnapshot>> thread_snapshots_owner;
std::vector<const ThreadSnapshot*> thread_snapshots; std::vector<const ThreadSnapshot*> thread_snapshots;
for (size_t index = 0; index < base::size(expect_threads); ++index) { for (size_t index = 0; index < std::size(expect_threads); ++index) {
thread_snapshots_owner.push_back(std::make_unique<TestThreadSnapshot>()); thread_snapshots_owner.push_back(std::make_unique<TestThreadSnapshot>());
TestThreadSnapshot* thread_snapshot = thread_snapshots_owner.back().get(); TestThreadSnapshot* thread_snapshot = thread_snapshots_owner.back().get();

View File

@ -16,7 +16,8 @@
#include <stdint.h> #include <stdint.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/logging.h" #include "base/logging.h"
#include "util/file/file_writer.h" #include "util/file/file_writer.h"
#include "util/numeric/safe_assignment.h" #include "util/numeric/safe_assignment.h"
@ -245,7 +246,7 @@ bool MinidumpWritable::WritePaddingAndObject(FileWriterInterface* file_writer) {
// The number of elements in kZeroes must be at least one less than the // The number of elements in kZeroes must be at least one less than the
// maximum Alignment() ever encountered. // maximum Alignment() ever encountered.
static constexpr uint8_t kZeroes[kMaximumAlignment - 1] = {}; static constexpr uint8_t kZeroes[kMaximumAlignment - 1] = {};
DCHECK_LE(leading_pad_bytes_, base::size(kZeroes)); DCHECK_LE(leading_pad_bytes_, std::size(kZeroes));
if (leading_pad_bytes_) { if (leading_pad_bytes_) {
if (!file_writer->Write(&kZeroes, leading_pad_bytes_)) { if (!file_writer->Write(&kZeroes, leading_pad_bytes_)) {

View File

@ -17,7 +17,8 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -128,8 +129,7 @@ void InitializeMinidumpContextAMD64(MinidumpContextAMD64* context,
context->ds = static_cast<uint16_t>(value++); context->ds = static_cast<uint16_t>(value++);
context->es = static_cast<uint16_t>(value++); context->es = static_cast<uint16_t>(value++);
context->ss = static_cast<uint16_t>(value++); context->ss = static_cast<uint16_t>(value++);
for (size_t index = 0; index < base::size(context->vector_register); for (size_t index = 0; index < std::size(context->vector_register); ++index) {
++index) {
context->vector_register[index].lo = value++; context->vector_register[index].lo = value++;
context->vector_register[index].hi = value++; context->vector_register[index].hi = value++;
} }
@ -152,7 +152,7 @@ void InitializeMinidumpContextARM(MinidumpContextARM* context, uint32_t seed) {
uint32_t value = seed; uint32_t value = seed;
for (size_t index = 0; index < base::size(context->regs); ++index) { for (size_t index = 0; index < std::size(context->regs); ++index) {
context->regs[index] = value++; context->regs[index] = value++;
} }
context->fp = value++; context->fp = value++;
@ -163,7 +163,7 @@ void InitializeMinidumpContextARM(MinidumpContextARM* context, uint32_t seed) {
context->pc = value++; context->pc = value++;
context->cpsr = value++; context->cpsr = value++;
for (size_t index = 0; index < base::size(context->vfp); ++index) { for (size_t index = 0; index < std::size(context->vfp); ++index) {
context->vfp[index] = value++; context->vfp[index] = value++;
} }
context->fpscr = value++; context->fpscr = value++;
@ -181,7 +181,7 @@ void InitializeMinidumpContextARM64(MinidumpContextARM64* context,
uint32_t value = seed; uint32_t value = seed;
for (size_t index = 0; index < base::size(context->regs); ++index) { for (size_t index = 0; index < std::size(context->regs); ++index) {
context->regs[index] = value++; context->regs[index] = value++;
} }
context->fp = value++; context->fp = value++;
@ -190,7 +190,7 @@ void InitializeMinidumpContextARM64(MinidumpContextARM64* context,
context->pc = value++; context->pc = value++;
context->cpsr = value++; context->cpsr = value++;
for (size_t index = 0; index < base::size(context->fpsimd); ++index) { for (size_t index = 0; index < std::size(context->fpsimd); ++index) {
context->fpsimd[index].lo = value++; context->fpsimd[index].lo = value++;
context->fpsimd[index].hi = value++; context->fpsimd[index].hi = value++;
} }
@ -210,7 +210,7 @@ void InitializeMinidumpContextMIPS(MinidumpContextMIPS* context,
uint32_t value = seed; uint32_t value = seed;
for (size_t index = 0; index < base::size(context->regs); ++index) { for (size_t index = 0; index < std::size(context->regs); ++index) {
context->regs[index] = value++; context->regs[index] = value++;
} }
@ -221,7 +221,7 @@ void InitializeMinidumpContextMIPS(MinidumpContextMIPS* context,
context->status = value++; context->status = value++;
context->cause = value++; context->cause = value++;
for (size_t index = 0; index < base::size(context->fpregs.fregs); ++index) { for (size_t index = 0; index < std::size(context->fpregs.fregs); ++index) {
context->fpregs.fregs[index]._fp_fregs = static_cast<float>(value++); context->fpregs.fregs[index]._fp_fregs = static_cast<float>(value++);
} }
@ -248,7 +248,7 @@ void InitializeMinidumpContextMIPS64(MinidumpContextMIPS64* context,
uint64_t value = seed; uint64_t value = seed;
for (size_t index = 0; index < base::size(context->regs); ++index) { for (size_t index = 0; index < std::size(context->regs); ++index) {
context->regs[index] = value++; context->regs[index] = value++;
} }
@ -259,7 +259,7 @@ void InitializeMinidumpContextMIPS64(MinidumpContextMIPS64* context,
context->status = value++; context->status = value++;
context->cause = value++; context->cause = value++;
for (size_t index = 0; index < base::size(context->fpregs.dregs); ++index) { for (size_t index = 0; index < std::size(context->fpregs.dregs); ++index) {
context->fpregs.dregs[index] = static_cast<double>(value++); context->fpregs.dregs[index] = static_cast<double>(value++);
} }
context->fpcsr = value++; context->fpcsr = value++;
@ -294,33 +294,33 @@ void ExpectMinidumpContextFxsave(const FxsaveType* expected,
EXPECT_EQ(observed->reserved_3, expected->reserved_3); EXPECT_EQ(observed->reserved_3, expected->reserved_3);
EXPECT_EQ(observed->mxcsr, expected->mxcsr); EXPECT_EQ(observed->mxcsr, expected->mxcsr);
EXPECT_EQ(observed->mxcsr_mask, expected->mxcsr_mask); EXPECT_EQ(observed->mxcsr_mask, expected->mxcsr_mask);
for (size_t st_mm_index = 0; st_mm_index < base::size(expected->st_mm); for (size_t st_mm_index = 0; st_mm_index < std::size(expected->st_mm);
++st_mm_index) { ++st_mm_index) {
SCOPED_TRACE(base::StringPrintf("st_mm_index %" PRIuS, st_mm_index)); SCOPED_TRACE(base::StringPrintf("st_mm_index %" PRIuS, st_mm_index));
EXPECT_EQ(BytesToHexString(observed->st_mm[st_mm_index].st, EXPECT_EQ(BytesToHexString(observed->st_mm[st_mm_index].st,
base::size(observed->st_mm[st_mm_index].st)), std::size(observed->st_mm[st_mm_index].st)),
BytesToHexString(expected->st_mm[st_mm_index].st, BytesToHexString(expected->st_mm[st_mm_index].st,
base::size(expected->st_mm[st_mm_index].st))); std::size(expected->st_mm[st_mm_index].st)));
EXPECT_EQ( EXPECT_EQ(
BytesToHexString(observed->st_mm[st_mm_index].st_reserved, BytesToHexString(observed->st_mm[st_mm_index].st_reserved,
base::size(observed->st_mm[st_mm_index].st_reserved)), std::size(observed->st_mm[st_mm_index].st_reserved)),
BytesToHexString(expected->st_mm[st_mm_index].st_reserved, BytesToHexString(expected->st_mm[st_mm_index].st_reserved,
base::size(expected->st_mm[st_mm_index].st_reserved))); std::size(expected->st_mm[st_mm_index].st_reserved)));
} }
for (size_t xmm_index = 0; xmm_index < base::size(expected->xmm); for (size_t xmm_index = 0; xmm_index < std::size(expected->xmm);
++xmm_index) { ++xmm_index) {
EXPECT_EQ(BytesToHexString(observed->xmm[xmm_index], EXPECT_EQ(BytesToHexString(observed->xmm[xmm_index],
base::size(observed->xmm[xmm_index])), std::size(observed->xmm[xmm_index])),
BytesToHexString(expected->xmm[xmm_index], BytesToHexString(expected->xmm[xmm_index],
base::size(expected->xmm[xmm_index]))) std::size(expected->xmm[xmm_index])))
<< "xmm_index " << xmm_index; << "xmm_index " << xmm_index;
} }
EXPECT_EQ( EXPECT_EQ(
BytesToHexString(observed->reserved_4, base::size(observed->reserved_4)), BytesToHexString(observed->reserved_4, std::size(observed->reserved_4)),
BytesToHexString(expected->reserved_4, base::size(expected->reserved_4))); BytesToHexString(expected->reserved_4, std::size(expected->reserved_4)));
EXPECT_EQ( EXPECT_EQ(
BytesToHexString(observed->available, base::size(observed->available)), BytesToHexString(observed->available, std::size(observed->available)),
BytesToHexString(expected->available, base::size(expected->available))); BytesToHexString(expected->available, std::size(expected->available)));
} }
} // namespace } // namespace
@ -345,11 +345,11 @@ void ExpectMinidumpContextX86(
EXPECT_EQ(observed->fsave.fpu_cs, expected.fsave.fpu_cs); EXPECT_EQ(observed->fsave.fpu_cs, expected.fsave.fpu_cs);
EXPECT_EQ(observed->fsave.fpu_dp, expected.fsave.fpu_dp); EXPECT_EQ(observed->fsave.fpu_dp, expected.fsave.fpu_dp);
EXPECT_EQ(observed->fsave.fpu_ds, expected.fsave.fpu_ds); EXPECT_EQ(observed->fsave.fpu_ds, expected.fsave.fpu_ds);
for (size_t index = 0; index < base::size(expected.fsave.st); ++index) { for (size_t index = 0; index < std::size(expected.fsave.st); ++index) {
EXPECT_EQ(BytesToHexString(observed->fsave.st[index], EXPECT_EQ(BytesToHexString(observed->fsave.st[index],
base::size(observed->fsave.st[index])), std::size(observed->fsave.st[index])),
BytesToHexString(expected.fsave.st[index], BytesToHexString(expected.fsave.st[index],
base::size(expected.fsave.st[index]))) std::size(expected.fsave.st[index])))
<< "index " << index; << "index " << index;
} }
if (snapshot) { if (snapshot) {
@ -448,8 +448,7 @@ void ExpectMinidumpContextAMD64(
ExpectMinidumpContextFxsave(&expected.fxsave, &observed->fxsave); ExpectMinidumpContextFxsave(&expected.fxsave, &observed->fxsave);
for (size_t index = 0; index < base::size(expected.vector_register); for (size_t index = 0; index < std::size(expected.vector_register); ++index) {
++index) {
if (snapshot) { if (snapshot) {
EXPECT_EQ(observed->vector_register[index].lo, 0u) << "index " << index; EXPECT_EQ(observed->vector_register[index].lo, 0u) << "index " << index;
EXPECT_EQ(observed->vector_register[index].hi, 0u) << "index " << index; EXPECT_EQ(observed->vector_register[index].hi, 0u) << "index " << index;
@ -489,7 +488,7 @@ void ExpectMinidumpContextARM(uint32_t expect_seed,
EXPECT_EQ(observed->context_flags, expected.context_flags); EXPECT_EQ(observed->context_flags, expected.context_flags);
for (size_t index = 0; index < base::size(expected.regs); ++index) { for (size_t index = 0; index < std::size(expected.regs); ++index) {
EXPECT_EQ(observed->regs[index], expected.regs[index]); EXPECT_EQ(observed->regs[index], expected.regs[index]);
} }
EXPECT_EQ(observed->fp, expected.fp); EXPECT_EQ(observed->fp, expected.fp);
@ -500,10 +499,10 @@ void ExpectMinidumpContextARM(uint32_t expect_seed,
EXPECT_EQ(observed->cpsr, expected.cpsr); EXPECT_EQ(observed->cpsr, expected.cpsr);
EXPECT_EQ(observed->fpscr, expected.fpscr); EXPECT_EQ(observed->fpscr, expected.fpscr);
for (size_t index = 0; index < base::size(expected.vfp); ++index) { for (size_t index = 0; index < std::size(expected.vfp); ++index) {
EXPECT_EQ(observed->vfp[index], expected.vfp[index]); EXPECT_EQ(observed->vfp[index], expected.vfp[index]);
} }
for (size_t index = 0; index < base::size(expected.extra); ++index) { for (size_t index = 0; index < std::size(expected.extra); ++index) {
EXPECT_EQ(observed->extra[index], snapshot ? 0 : expected.extra[index]); EXPECT_EQ(observed->extra[index], snapshot ? 0 : expected.extra[index]);
} }
} }
@ -516,14 +515,14 @@ void ExpectMinidumpContextARM64(uint32_t expect_seed,
EXPECT_EQ(observed->context_flags, expected.context_flags); EXPECT_EQ(observed->context_flags, expected.context_flags);
for (size_t index = 0; index < base::size(expected.regs); ++index) { for (size_t index = 0; index < std::size(expected.regs); ++index) {
EXPECT_EQ(observed->regs[index], expected.regs[index]); EXPECT_EQ(observed->regs[index], expected.regs[index]);
} }
EXPECT_EQ(observed->cpsr, expected.cpsr); EXPECT_EQ(observed->cpsr, expected.cpsr);
EXPECT_EQ(observed->fpsr, expected.fpsr); EXPECT_EQ(observed->fpsr, expected.fpsr);
EXPECT_EQ(observed->fpcr, expected.fpcr); EXPECT_EQ(observed->fpcr, expected.fpcr);
for (size_t index = 0; index < base::size(expected.fpsimd); ++index) { for (size_t index = 0; index < std::size(expected.fpsimd); ++index) {
EXPECT_EQ(observed->fpsimd[index].lo, expected.fpsimd[index].lo); EXPECT_EQ(observed->fpsimd[index].lo, expected.fpsimd[index].lo);
EXPECT_EQ(observed->fpsimd[index].hi, expected.fpsimd[index].hi); EXPECT_EQ(observed->fpsimd[index].hi, expected.fpsimd[index].hi);
} }
@ -537,7 +536,7 @@ void ExpectMinidumpContextMIPS(uint32_t expect_seed,
EXPECT_EQ(observed->context_flags, expected.context_flags); EXPECT_EQ(observed->context_flags, expected.context_flags);
for (size_t index = 0; index < base::size(expected.regs); ++index) { for (size_t index = 0; index < std::size(expected.regs); ++index) {
EXPECT_EQ(observed->regs[index], expected.regs[index]); EXPECT_EQ(observed->regs[index], expected.regs[index]);
} }
@ -548,7 +547,7 @@ void ExpectMinidumpContextMIPS(uint32_t expect_seed,
EXPECT_EQ(observed->status, expected.status); EXPECT_EQ(observed->status, expected.status);
EXPECT_EQ(observed->cause, expected.cause); EXPECT_EQ(observed->cause, expected.cause);
for (size_t index = 0; index < base::size(expected.fpregs.fregs); ++index) { for (size_t index = 0; index < std::size(expected.fpregs.fregs); ++index) {
EXPECT_EQ(observed->fpregs.fregs[index]._fp_fregs, EXPECT_EQ(observed->fpregs.fregs[index]._fp_fregs,
expected.fpregs.fregs[index]._fp_fregs); expected.fpregs.fregs[index]._fp_fregs);
} }
@ -570,7 +569,7 @@ void ExpectMinidumpContextMIPS64(uint32_t expect_seed,
EXPECT_EQ(observed->context_flags, expected.context_flags); EXPECT_EQ(observed->context_flags, expected.context_flags);
for (size_t index = 0; index < base::size(expected.regs); ++index) { for (size_t index = 0; index < std::size(expected.regs); ++index) {
EXPECT_EQ(observed->regs[index], expected.regs[index]); EXPECT_EQ(observed->regs[index], expected.regs[index]);
} }
@ -581,7 +580,7 @@ void ExpectMinidumpContextMIPS64(uint32_t expect_seed,
EXPECT_EQ(observed->status, expected.status); EXPECT_EQ(observed->status, expected.status);
EXPECT_EQ(observed->cause, expected.cause); EXPECT_EQ(observed->cause, expected.cause);
for (size_t index = 0; index < base::size(expected.fpregs.dregs); ++index) { for (size_t index = 0; index < std::size(expected.fpregs.dregs); ++index) {
EXPECT_EQ(observed->fpregs.dregs[index], expected.fpregs.dregs[index]); EXPECT_EQ(observed->fpregs.dregs[index], expected.fpregs.dregs[index]);
} }
EXPECT_EQ(observed->fpcsr, expected.fpcsr); EXPECT_EQ(observed->fpcsr, expected.fpcsr);

View File

@ -16,10 +16,10 @@
#include <stdint.h> #include <stdint.h>
#include <iterator>
#include <limits> #include <limits>
#include <memory> #include <memory>
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "snapshot/memory_snapshot.h" #include "snapshot/memory_snapshot.h"
@ -99,17 +99,17 @@ void CaptureMemory::PointedToByContext(const CPUContext& context,
#elif defined(ARCH_CPU_ARM_FAMILY) #elif defined(ARCH_CPU_ARM_FAMILY)
if (context.architecture == kCPUArchitectureARM64) { if (context.architecture == kCPUArchitectureARM64) {
MaybeCaptureMemoryAround(delegate, context.arm64->pc); MaybeCaptureMemoryAround(delegate, context.arm64->pc);
for (size_t i = 0; i < base::size(context.arm64->regs); ++i) { for (size_t i = 0; i < std::size(context.arm64->regs); ++i) {
MaybeCaptureMemoryAround(delegate, context.arm64->regs[i]); MaybeCaptureMemoryAround(delegate, context.arm64->regs[i]);
} }
} else { } else {
MaybeCaptureMemoryAround(delegate, context.arm->pc); MaybeCaptureMemoryAround(delegate, context.arm->pc);
for (size_t i = 0; i < base::size(context.arm->regs); ++i) { for (size_t i = 0; i < std::size(context.arm->regs); ++i) {
MaybeCaptureMemoryAround(delegate, context.arm->regs[i]); MaybeCaptureMemoryAround(delegate, context.arm->regs[i]);
} }
} }
#elif defined(ARCH_CPU_MIPS_FAMILY) #elif defined(ARCH_CPU_MIPS_FAMILY)
for (size_t i = 0; i < base::size(context.mipsel->regs); ++i) { for (size_t i = 0; i < std::size(context.mipsel->regs); ++i) {
MaybeCaptureMemoryAround(delegate, context.mipsel->regs[i]); MaybeCaptureMemoryAround(delegate, context.mipsel->regs[i]);
} }
#else #else

View File

@ -17,7 +17,8 @@
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/notreached.h" #include "base/notreached.h"
#include "util/misc/arraysize.h" #include "util/misc/arraysize.h"
#include "util/misc/implicit_cast.h" #include "util/misc/implicit_cast.h"
@ -58,7 +59,7 @@ void CPUContextX86::FxsaveToFsave(const Fxsave& fxsave, Fsave* fsave) {
fsave->reserved_4 = 0; fsave->reserved_4 = 0;
static_assert(ArraySize(fsave->st) == ArraySize(fxsave.st_mm), static_assert(ArraySize(fsave->st) == ArraySize(fxsave.st_mm),
"FPU stack registers must be equivalent"); "FPU stack registers must be equivalent");
for (size_t index = 0; index < base::size(fsave->st); ++index) { for (size_t index = 0; index < std::size(fsave->st); ++index) {
memcpy(fsave->st[index], fxsave.st_mm[index].st, sizeof(fsave->st[index])); memcpy(fsave->st[index], fxsave.st_mm[index].st, sizeof(fsave->st[index]));
} }
} }
@ -80,7 +81,7 @@ void CPUContextX86::FsaveToFxsave(const Fsave& fsave, Fxsave* fxsave) {
fxsave->mxcsr_mask = 0; fxsave->mxcsr_mask = 0;
static_assert(ArraySize(fxsave->st_mm) == ArraySize(fsave.st), static_assert(ArraySize(fxsave->st_mm) == ArraySize(fsave.st),
"FPU stack registers must be equivalent"); "FPU stack registers must be equivalent");
for (size_t index = 0; index < base::size(fsave.st); ++index) { for (size_t index = 0; index < std::size(fsave.st); ++index) {
memcpy(fxsave->st_mm[index].st, fsave.st[index], sizeof(fsave.st[index])); memcpy(fxsave->st_mm[index].st, fsave.st[index], sizeof(fsave.st[index]));
memset(fxsave->st_mm[index].st_reserved, memset(fxsave->st_mm[index].st_reserved,
0, 0,

View File

@ -18,7 +18,8 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "test/hex_string.h" #include "test/hex_string.h"
@ -124,7 +125,7 @@ TEST(CPUContextX86, FxsaveToFsave) {
&fxsave.st_mm[6].st, kExponentAllZero, false, kFractionAllZero); &fxsave.st_mm[6].st, kExponentAllZero, false, kFractionAllZero);
SetX87Register( SetX87Register(
&fxsave.st_mm[7].st, kExponentNormal, true, kFractionNormal); // valid &fxsave.st_mm[7].st, kExponentNormal, true, kFractionNormal); // valid
for (size_t index = 0; index < base::size(fxsave.st_mm); ++index) { for (size_t index = 0; index < std::size(fxsave.st_mm); ++index) {
memset(&fxsave.st_mm[index].st_reserved, memset(&fxsave.st_mm[index].st_reserved,
0x5a, 0x5a,
sizeof(fxsave.st_mm[index].st_reserved)); sizeof(fxsave.st_mm[index].st_reserved));
@ -148,10 +149,10 @@ TEST(CPUContextX86, FxsaveToFsave) {
EXPECT_EQ(fsave.fpu_dp, fxsave.fpu_dp); EXPECT_EQ(fsave.fpu_dp, fxsave.fpu_dp);
EXPECT_EQ(fsave.fpu_ds, fxsave.fpu_ds); EXPECT_EQ(fsave.fpu_ds, fxsave.fpu_ds);
EXPECT_EQ(fsave.reserved_4, 0); EXPECT_EQ(fsave.reserved_4, 0);
for (size_t index = 0; index < base::size(fsave.st); ++index) { for (size_t index = 0; index < std::size(fsave.st); ++index) {
EXPECT_EQ(BytesToHexString(fsave.st[index], base::size(fsave.st[index])), EXPECT_EQ(BytesToHexString(fsave.st[index], std::size(fsave.st[index])),
BytesToHexString(fxsave.st_mm[index].st, BytesToHexString(fxsave.st_mm[index].st,
base::size(fxsave.st_mm[index].st))) std::size(fxsave.st_mm[index].st)))
<< "index " << index; << "index " << index;
} }
} }
@ -204,14 +205,14 @@ TEST(CPUContextX86, FsaveToFxsave) {
EXPECT_EQ(fxsave.reserved_3, 0); EXPECT_EQ(fxsave.reserved_3, 0);
EXPECT_EQ(fxsave.mxcsr, 0u); EXPECT_EQ(fxsave.mxcsr, 0u);
EXPECT_EQ(fxsave.mxcsr_mask, 0u); EXPECT_EQ(fxsave.mxcsr_mask, 0u);
for (size_t index = 0; index < base::size(fxsave.st_mm); ++index) { for (size_t index = 0; index < std::size(fxsave.st_mm); ++index) {
EXPECT_EQ(BytesToHexString(fxsave.st_mm[index].st, EXPECT_EQ(BytesToHexString(fxsave.st_mm[index].st,
base::size(fxsave.st_mm[index].st)), std::size(fxsave.st_mm[index].st)),
BytesToHexString(fsave.st[index], base::size(fsave.st[index]))) BytesToHexString(fsave.st[index], std::size(fsave.st[index])))
<< "index " << index; << "index " << index;
EXPECT_EQ(BytesToHexString(fxsave.st_mm[index].st_reserved, EXPECT_EQ(BytesToHexString(fxsave.st_mm[index].st_reserved,
base::size(fxsave.st_mm[index].st_reserved)), std::size(fxsave.st_mm[index].st_reserved)),
std::string(base::size(fxsave.st_mm[index].st_reserved) * 2, '0')) std::string(std::size(fxsave.st_mm[index].st_reserved) * 2, '0'))
<< "index " << index; << "index " << index;
} }
size_t unused_len = sizeof(fxsave) - offsetof(decltype(fxsave), xmm); size_t unused_len = sizeof(fxsave) - offsetof(decltype(fxsave), xmm);
@ -318,7 +319,7 @@ TEST(CPUContextX86, FxsaveToFsaveTagWord) {
// In this set, everything is valid. // In this set, everything is valid.
fsw = 0 << 11; // top = 0: logical 0-7 maps to physical 0-7 fsw = 0 << 11; // top = 0: logical 0-7 maps to physical 0-7
fxsave_tag = 0xff; // nothing empty fxsave_tag = 0xff; // nothing empty
for (size_t index = 0; index < base::size(st_mm); ++index) { for (size_t index = 0; index < std::size(st_mm); ++index) {
SetX87OrMMXRegister(&st_mm[index], kExponentNormal, true, kFractionAllZero); SetX87OrMMXRegister(&st_mm[index], kExponentNormal, true, kFractionAllZero);
} }
EXPECT_EQ(CPUContextX86::FxsaveToFsaveTagWord(fsw, fxsave_tag, st_mm), 0); EXPECT_EQ(CPUContextX86::FxsaveToFsaveTagWord(fsw, fxsave_tag, st_mm), 0);

View File

@ -14,8 +14,9 @@
#include "snapshot/fuchsia/memory_map_region_snapshot_fuchsia.h" #include "snapshot/fuchsia/memory_map_region_snapshot_fuchsia.h"
#include <iterator>
#include "base/check_op.h" #include "base/check_op.h"
#include "base/cxx17_backports.h"
namespace crashpad { namespace crashpad {
namespace internal { namespace internal {
@ -50,7 +51,7 @@ uint32_t MmuFlagsToProtectFlags(zx_vm_option_t flags) {
const uint32_t index = const uint32_t index =
flags & (ZX_VM_PERM_READ | ZX_VM_PERM_WRITE | ZX_VM_PERM_EXECUTE); flags & (ZX_VM_PERM_READ | ZX_VM_PERM_WRITE | ZX_VM_PERM_EXECUTE);
DCHECK_LT(index, base::size(mapping)); DCHECK_LT(index, std::size(mapping));
const uint32_t protect_flags = mapping[index]; const uint32_t protect_flags = mapping[index];
DCHECK_NE(protect_flags, 0u); DCHECK_NE(protect_flags, 0u);

View File

@ -20,7 +20,8 @@
#include <zircon/syscalls/port.h> #include <zircon/syscalls/port.h>
#include <zircon/types.h> #include <zircon/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "test/multiprocess_exec.h" #include "test/multiprocess_exec.h"
#include "test/test_paths.h" #include "test/test_paths.h"
@ -35,7 +36,7 @@ TEST(ProcessReaderFuchsia, SelfBasic) {
ASSERT_TRUE(process_reader.Initialize(*zx::process::self())); ASSERT_TRUE(process_reader.Initialize(*zx::process::self()));
static constexpr char kTestMemory[] = "Some test memory"; static constexpr char kTestMemory[] = "Some test memory";
char buffer[base::size(kTestMemory)]; char buffer[std::size(kTestMemory)];
ASSERT_TRUE(process_reader.Memory()->Read( ASSERT_TRUE(process_reader.Memory()->Read(
reinterpret_cast<zx_vaddr_t>(kTestMemory), sizeof(kTestMemory), &buffer)); reinterpret_cast<zx_vaddr_t>(kTestMemory), sizeof(kTestMemory), &buffer));
EXPECT_STREQ(kTestMemory, buffer); EXPECT_STREQ(kTestMemory, buffer);

View File

@ -12,17 +12,18 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "snapshot/fuchsia/memory_map_region_snapshot_fuchsia.h" #include "snapshot/fuchsia/process_snapshot_fuchsia.h"
#include <dbghelp.h> #include <dbghelp.h>
#include <zircon/syscalls.h> #include <zircon/syscalls.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/fuchsia/fuchsia_logging.h" #include "base/fuchsia/fuchsia_logging.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "snapshot/fuchsia/process_snapshot_fuchsia.h" #include "snapshot/fuchsia/memory_map_region_snapshot_fuchsia.h"
#include "test/multiprocess_exec.h" #include "test/multiprocess_exec.h"
#include "util/fuchsia/koid_utilities.h" #include "util/fuchsia/koid_utilities.h"
#include "util/fuchsia/scoped_task_suspend.h" #include "util/fuchsia/scoped_task_suspend.h"
@ -111,8 +112,8 @@ class AddressSpaceTest : public MultiprocessExec {
private: private:
void MultiprocessParent() override { void MultiprocessParent() override {
uintptr_t test_addresses[base::size(kTestMappingPermAndSizes)]; uintptr_t test_addresses[std::size(kTestMappingPermAndSizes)];
for (size_t i = 0; i < base::size(test_addresses); ++i) { for (size_t i = 0; i < std::size(test_addresses); ++i) {
ASSERT_TRUE(ReadFileExactly( ASSERT_TRUE(ReadFileExactly(
ReadPipeHandle(), &test_addresses[i], sizeof(test_addresses[i]))); ReadPipeHandle(), &test_addresses[i], sizeof(test_addresses[i])));
} }
@ -122,7 +123,7 @@ class AddressSpaceTest : public MultiprocessExec {
ProcessSnapshotFuchsia process_snapshot; ProcessSnapshotFuchsia process_snapshot;
ASSERT_TRUE(process_snapshot.Initialize(*ChildProcess())); ASSERT_TRUE(process_snapshot.Initialize(*ChildProcess()));
for (size_t i = 0; i < base::size(test_addresses); ++i) { for (size_t i = 0; i < std::size(test_addresses); ++i) {
const auto& t = kTestMappingPermAndSizes[i]; const auto& t = kTestMappingPermAndSizes[i];
EXPECT_TRUE(HasSingleMatchingMapping(process_snapshot.MemoryMap(), EXPECT_TRUE(HasSingleMatchingMapping(process_snapshot.MemoryMap(),
test_addresses[i], test_addresses[i],

View File

@ -21,8 +21,9 @@
#include <ucontext.h> #include <ucontext.h>
#include <unistd.h> #include <unistd.h>
#include <iterator>
#include "base/bit_cast.h" #include "base/bit_cast.h"
#include "base/cxx17_backports.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "snapshot/cpu_architecture.h" #include "snapshot/cpu_architecture.h"
@ -170,7 +171,7 @@ void InitializeContext(NativeCPUContext* context) {
test_context->vfp.head.magic = VFP_MAGIC; test_context->vfp.head.magic = VFP_MAGIC;
test_context->vfp.head.size = sizeof(test_context->vfp); test_context->vfp.head.size = sizeof(test_context->vfp);
memset(&test_context->vfp.context, 'v', sizeof(test_context->vfp.context)); memset(&test_context->vfp.context, 'v', sizeof(test_context->vfp.context));
for (size_t reg = 0; reg < base::size(test_context->vfp.context.vfp.fpregs); for (size_t reg = 0; reg < std::size(test_context->vfp.context.vfp.fpregs);
++reg) { ++reg) {
test_context->vfp.context.vfp.fpregs[reg] = reg; test_context->vfp.context.vfp.fpregs[reg] = reg;
} }
@ -218,7 +219,7 @@ struct TestCoprocessorContext {
void InitializeContext(NativeCPUContext* context) { void InitializeContext(NativeCPUContext* context) {
memset(context, 'x', sizeof(*context)); memset(context, 'x', sizeof(*context));
for (size_t index = 0; index < base::size(context->uc_mcontext.regs); for (size_t index = 0; index < std::size(context->uc_mcontext.regs);
++index) { ++index) {
context->uc_mcontext.regs[index] = index; context->uc_mcontext.regs[index] = index;
} }
@ -237,7 +238,7 @@ void InitializeContext(NativeCPUContext* context) {
test_context->fpsimd.head.size = sizeof(test_context->fpsimd); test_context->fpsimd.head.size = sizeof(test_context->fpsimd);
test_context->fpsimd.fpsr = 1; test_context->fpsimd.fpsr = 1;
test_context->fpsimd.fpcr = 2; test_context->fpsimd.fpcr = 2;
for (size_t reg = 0; reg < base::size(test_context->fpsimd.vregs); ++reg) { for (size_t reg = 0; reg < std::size(test_context->fpsimd.vregs); ++reg) {
test_context->fpsimd.vregs[reg] = reg; test_context->fpsimd.vregs[reg] = reg;
} }
@ -270,7 +271,7 @@ void ExpectContext(const CPUContext& actual, const NativeCPUContext& expected) {
using NativeCPUContext = ucontext_t; using NativeCPUContext = ucontext_t;
void InitializeContext(NativeCPUContext* context) { void InitializeContext(NativeCPUContext* context) {
for (size_t reg = 0; reg < base::size(context->uc_mcontext.gregs); ++reg) { for (size_t reg = 0; reg < std::size(context->uc_mcontext.gregs); ++reg) {
context->uc_mcontext.gregs[reg] = reg; context->uc_mcontext.gregs[reg] = reg;
} }
memset(&context->uc_mcontext.fpregs, 44, sizeof(context->uc_mcontext.fpregs)); memset(&context->uc_mcontext.fpregs, 44, sizeof(context->uc_mcontext.fpregs));
@ -285,7 +286,7 @@ void ExpectContext(const CPUContext& actual, const NativeCPUContext& expected) {
#define CPU_ARCH_NAME mips64 #define CPU_ARCH_NAME mips64
#endif #endif
for (size_t reg = 0; reg < base::size(expected.uc_mcontext.gregs); ++reg) { for (size_t reg = 0; reg < std::size(expected.uc_mcontext.gregs); ++reg) {
EXPECT_EQ(actual.CPU_ARCH_NAME->regs[reg], expected.uc_mcontext.gregs[reg]); EXPECT_EQ(actual.CPU_ARCH_NAME->regs[reg], expected.uc_mcontext.gregs[reg]);
} }

View File

@ -26,12 +26,12 @@
#include <sys/syscall.h> #include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
#include <iterator>
#include <map> #include <map>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/memory/free_deleter.h" #include "base/memory/free_deleter.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
@ -88,7 +88,7 @@ TEST(ProcessReaderLinux, SelfBasic) {
EXPECT_EQ(process_reader.ParentProcessID(), getppid()); EXPECT_EQ(process_reader.ParentProcessID(), getppid());
static constexpr char kTestMemory[] = "Some test memory"; static constexpr char kTestMemory[] = "Some test memory";
char buffer[base::size(kTestMemory)]; char buffer[std::size(kTestMemory)];
ASSERT_TRUE(process_reader.Memory()->Read( ASSERT_TRUE(process_reader.Memory()->Read(
reinterpret_cast<LinuxVMAddress>(kTestMemory), reinterpret_cast<LinuxVMAddress>(kTestMemory),
sizeof(kTestMemory), sizeof(kTestMemory),

View File

@ -18,10 +18,10 @@
#include <mach-o/nlist.h> #include <mach-o/nlist.h>
#include <string.h> #include <string.h>
#include <iterator>
#include <limits> #include <limits>
#include <utility> #include <utility>
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "client/crashpad_info.h" #include "client/crashpad_info.h"
@ -183,7 +183,7 @@ bool MachOImageReader::Initialize(ProcessReaderMac* process_reader,
// This vector is parallel to the kLoadCommandReaders array, and tracks // This vector is parallel to the kLoadCommandReaders array, and tracks
// whether a singleton load command matching the |command| field has been // whether a singleton load command matching the |command| field has been
// found yet. // found yet.
std::vector<uint32_t> singleton_indices(base::size(kLoadCommandReaders), std::vector<uint32_t> singleton_indices(std::size(kLoadCommandReaders),
kInvalidSegmentIndex); kInvalidSegmentIndex);
size_t offset = mach_header.Size(); size_t offset = mach_header.Size();
@ -236,8 +236,7 @@ bool MachOImageReader::Initialize(ProcessReaderMac* process_reader,
return false; return false;
} }
for (size_t reader_index = 0; for (size_t reader_index = 0; reader_index < std::size(kLoadCommandReaders);
reader_index < base::size(kLoadCommandReaders);
++reader_index) { ++reader_index) {
if (load_command.cmd != kLoadCommandReaders[reader_index].command) { if (load_command.cmd != kLoadCommandReaders[reader_index].command) {
continue; continue;

View File

@ -16,7 +16,8 @@
#include <mach-o/loader.h> #include <mach-o/loader.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -63,7 +64,7 @@ TEST(MachOImageSegmentReader, SegmentNameString) {
SEG_IMPORT, SEG_IMPORT,
}; };
for (size_t index = 0; index < base::size(kSegmentTestData); ++index) { for (size_t index = 0; index < std::size(kSegmentTestData); ++index) {
EXPECT_EQ( EXPECT_EQ(
MachOImageSegmentReader::SegmentNameString(kSegmentTestData[index]), MachOImageSegmentReader::SegmentNameString(kSegmentTestData[index]),
kSegmentTestData[index]) kSegmentTestData[index])
@ -106,7 +107,7 @@ TEST(MachOImageSegmentReader, SectionNameString) {
SECT_ICON_TIFF, SECT_ICON_TIFF,
}; };
for (size_t index = 0; index < base::size(kSectionTestData); ++index) { for (size_t index = 0; index < std::size(kSectionTestData); ++index) {
EXPECT_EQ( EXPECT_EQ(
MachOImageSegmentReader::SectionNameString(kSectionTestData[index]), MachOImageSegmentReader::SectionNameString(kSectionTestData[index]),
kSectionTestData[index]) kSectionTestData[index])
@ -169,7 +170,7 @@ TEST(MachOImageSegmentReader, SegmentAndSectionNameString) {
{SEG_IMPORT, "", "__IMPORT,"}, {SEG_IMPORT, "", "__IMPORT,"},
}; };
for (size_t index = 0; index < base::size(kSegmentAndSectionTestData); for (size_t index = 0; index < std::size(kSegmentAndSectionTestData);
++index) { ++index) {
const auto& test = kSegmentAndSectionTestData[index]; const auto& test = kSegmentAndSectionTestData[index];
EXPECT_EQ(MachOImageSegmentReader::SegmentAndSectionNameString( EXPECT_EQ(MachOImageSegmentReader::SegmentAndSectionNameString(

View File

@ -25,11 +25,11 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <iterator>
#include <map> #include <map>
#include <utility> #include <utility>
#include "base/check_op.h" #include "base/check_op.h"
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/mach_logging.h" #include "base/mac/mach_logging.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
@ -68,7 +68,7 @@ TEST(ProcessReaderMac, SelfBasic) {
EXPECT_EQ(process_reader.ParentProcessID(), getppid()); EXPECT_EQ(process_reader.ParentProcessID(), getppid());
static constexpr char kTestMemory[] = "Some test memory"; static constexpr char kTestMemory[] = "Some test memory";
char buffer[base::size(kTestMemory)]; char buffer[std::size(kTestMemory)];
ASSERT_TRUE(process_reader.Memory()->Read( ASSERT_TRUE(process_reader.Memory()->Read(
FromPointerCast<mach_vm_address_t>(kTestMemory), FromPointerCast<mach_vm_address_t>(kTestMemory),
sizeof(kTestMemory), sizeof(kTestMemory),
@ -702,11 +702,11 @@ class ScopedOpenCLNoOpKernel {
const size_t source_lengths[] = { const size_t source_lengths[] = {
strlen(sources[0]), strlen(sources[0]),
}; };
static_assert(base::size(sources) == base::size(source_lengths), static_assert(std::size(sources) == std::size(source_lengths),
"arrays must be parallel"); "arrays must be parallel");
program_ = clCreateProgramWithSource( program_ = clCreateProgramWithSource(
context_, base::size(sources), sources, source_lengths, &rv); context_, std::size(sources), sources, source_lengths, &rv);
ASSERT_EQ(rv, CL_SUCCESS) << "clCreateProgramWithSource"; ASSERT_EQ(rv, CL_SUCCESS) << "clCreateProgramWithSource";
rv = clBuildProgram( rv = clBuildProgram(

View File

@ -18,9 +18,9 @@
#include <string.h> #include <string.h>
#include <uuid/uuid.h> #include <uuid/uuid.h>
#include <iterator>
#include <memory> #include <memory>
#include "base/cxx17_backports.h"
#include "snapshot/mac/process_types/internal.h" #include "snapshot/mac/process_types/internal.h"
#include "util/process/process_memory_mac.h" #include "util/process/process_memory_mac.h"
@ -74,7 +74,7 @@ using UInt64Array4 = uint64_t[4];
template <> template <>
inline void Assign<UInt64Array4, UInt32Array4>(UInt64Array4* destination, inline void Assign<UInt64Array4, UInt32Array4>(UInt64Array4* destination,
const UInt32Array4& source) { const UInt32Array4& source) {
for (size_t index = 0; index < base::size(source); ++index) { for (size_t index = 0; index < std::size(source); ++index) {
(*destination)[index] = source[index]; (*destination)[index] = source[index];
} }
} }

View File

@ -12,21 +12,20 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "snapshot/mac/process_types.h"
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <algorithm> #include <algorithm>
#include <iterator>
#include <limits> #include <limits>
#include <type_traits> #include <type_traits>
#include "base/check_op.h" #include "base/check_op.h"
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/numerics/safe_math.h" #include "base/numerics/safe_math.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "snapshot/mac/process_types.h"
#include "snapshot/mac/process_types/internal.h" #include "snapshot/mac/process_types/internal.h"
#include "util/mac/mac_util.h" #include "util/mac/mac_util.h"
#include "util/process/process_memory_mac.h" #include "util/process/process_memory_mac.h"
@ -150,8 +149,8 @@ size_t dyld_all_image_infos<Traits>::ExpectedSizeForVersion(
sizeof(dyld_all_image_infos<Traits>), // 18 sizeof(dyld_all_image_infos<Traits>), // 18
}; };
if (version >= base::size(kSizeForVersion)) { if (version >= std::size(kSizeForVersion)) {
return kSizeForVersion[base::size(kSizeForVersion) - 1]; return kSizeForVersion[std::size(kSizeForVersion) - 1];
} }
static_assert(std::is_unsigned<decltype(version)>::value, static_assert(std::is_unsigned<decltype(version)>::value,

View File

@ -18,10 +18,10 @@
#include <mach/mach.h> #include <mach/mach.h>
#include <string.h> #include <string.h>
#include <iterator>
#include <limits> #include <limits>
#include <vector> #include <vector>
#include "base/cxx17_backports.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -172,7 +172,7 @@ TEST(ProcessTypes, DyldImagesSelf) {
{16, kUnsupported, 328}, {16, kUnsupported, 328},
{17, kUnsupported, 368}, {17, kUnsupported, 368},
}; };
for (size_t index = 0; index < base::size(kVersionsAndSizes); ++index) { for (size_t index = 0; index < std::size(kVersionsAndSizes); ++index) {
uint32_t version = kVersionsAndSizes[index].version; uint32_t version = kVersionsAndSizes[index].version;
SCOPED_TRACE(base::StringPrintf("index %zu, version %u", index, version)); SCOPED_TRACE(base::StringPrintf("index %zu, version %u", index, version));
@ -325,7 +325,7 @@ TEST(ProcessTypes, DyldImagesSelf) {
self_image_infos->sharedCacheBaseAddress); self_image_infos->sharedCacheBaseAddress);
EXPECT_EQ(proctype_image_infos.dyldPath, EXPECT_EQ(proctype_image_infos.dyldPath,
reinterpret_cast<uint64_t>(self_image_infos->dyldPath)); reinterpret_cast<uint64_t>(self_image_infos->dyldPath));
for (size_t index = 0; index < base::size(self_image_infos->notifyPorts); for (size_t index = 0; index < std::size(self_image_infos->notifyPorts);
++index) { ++index) {
EXPECT_EQ(proctype_image_infos.notifyPorts[index], EXPECT_EQ(proctype_image_infos.notifyPorts[index],
self_image_infos->notifyPorts[index]) self_image_infos->notifyPorts[index])
@ -345,7 +345,7 @@ TEST(ProcessTypes, DyldImagesSelf) {
// process_types version. Its difficult to compare the reserved fields in // process_types version. Its difficult to compare the reserved fields in
// these older SDKs, so only do it where the declarations match. // these older SDKs, so only do it where the declarations match.
if (proctype_image_infos.version >= 14) { if (proctype_image_infos.version >= 14) {
for (size_t index = 0; index < base::size(proctype_image_infos.reserved); for (size_t index = 0; index < std::size(proctype_image_infos.reserved);
++index) { ++index) {
EXPECT_EQ(proctype_image_infos.reserved[index], EXPECT_EQ(proctype_image_infos.reserved[index],
implicit_cast<uint64_t>(self_image_infos->reserved[index])) implicit_cast<uint64_t>(self_image_infos->reserved[index]))

View File

@ -16,7 +16,8 @@
#include <string.h> #include <string.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/logging.h" #include "base/logging.h"
#include "minidump/minidump_context.h" #include "minidump/minidump_context.h"
@ -147,7 +148,7 @@ bool MinidumpContextConverter::Initialize(
return false; return false;
} }
for (size_t i = 0; i < base::size(src->regs); i++) { for (size_t i = 0; i < std::size(src->regs); i++) {
context_.arm->regs[i] = src->regs[i]; context_.arm->regs[i] = src->regs[i];
} }
@ -159,7 +160,7 @@ bool MinidumpContextConverter::Initialize(
context_.arm->cpsr = src->cpsr; context_.arm->cpsr = src->cpsr;
context_.arm->vfp_regs.fpscr = src->fpscr; context_.arm->vfp_regs.fpscr = src->fpscr;
for (size_t i = 0; i < base::size(src->vfp); i++) { for (size_t i = 0; i < std::size(src->vfp); i++) {
context_.arm->vfp_regs.vfp[i] = src->vfp[i]; context_.arm->vfp_regs.vfp[i] = src->vfp[i];
} }
@ -179,14 +180,14 @@ bool MinidumpContextConverter::Initialize(
return false; return false;
} }
for (size_t i = 0; i < base::size(src->regs); i++) { for (size_t i = 0; i < std::size(src->regs); i++) {
context_.arm64->regs[i] = src->regs[i]; context_.arm64->regs[i] = src->regs[i];
} }
context_.arm64->regs[29] = src->fp; context_.arm64->regs[29] = src->fp;
context_.arm64->regs[30] = src->lr; context_.arm64->regs[30] = src->lr;
for (size_t i = 0; i < base::size(src->fpsimd); i++) { for (size_t i = 0; i < std::size(src->fpsimd); i++) {
context_.arm64->fpsimd[i] = src->fpsimd[i]; context_.arm64->fpsimd[i] = src->fpsimd[i];
} }
@ -208,7 +209,7 @@ bool MinidumpContextConverter::Initialize(
return false; return false;
} }
for (size_t i = 0; i < base::size(src->regs); i++) { for (size_t i = 0; i < std::size(src->regs); i++) {
context_.mipsel->regs[i] = src->regs[i]; context_.mipsel->regs[i] = src->regs[i];
} }
@ -216,7 +217,7 @@ bool MinidumpContextConverter::Initialize(
context_.mipsel->mdlo = static_cast<uint32_t>(src->mdlo); context_.mipsel->mdlo = static_cast<uint32_t>(src->mdlo);
context_.mipsel->dsp_control = src->dsp_control; context_.mipsel->dsp_control = src->dsp_control;
for (size_t i = 0; i < base::size(src->hi); i++) { for (size_t i = 0; i < std::size(src->hi); i++) {
context_.mipsel->hi[i] = src->hi[i]; context_.mipsel->hi[i] = src->hi[i];
context_.mipsel->lo[i] = src->lo[i]; context_.mipsel->lo[i] = src->lo[i];
} }
@ -244,7 +245,7 @@ bool MinidumpContextConverter::Initialize(
return false; return false;
} }
for (size_t i = 0; i < base::size(src->regs); i++) { for (size_t i = 0; i < std::size(src->regs); i++) {
context_.mips64->regs[i] = src->regs[i]; context_.mips64->regs[i] = src->regs[i];
} }
@ -252,7 +253,7 @@ bool MinidumpContextConverter::Initialize(
context_.mips64->mdlo = src->mdlo; context_.mips64->mdlo = src->mdlo;
context_.mips64->dsp_control = src->dsp_control; context_.mips64->dsp_control = src->dsp_control;
for (size_t i = 0; i < base::size(src->hi); i++) { for (size_t i = 0; i < std::size(src->hi); i++) {
context_.mips64->hi[i] = src->hi[i]; context_.mips64->hi[i] = src->hi[i];
context_.mips64->lo[i] = src->lo[i]; context_.mips64->lo[i] = src->lo[i];
} }

View File

@ -19,9 +19,9 @@
#include <string.h> #include <string.h>
#include <algorithm> #include <algorithm>
#include <iterator>
#include <memory> #include <memory>
#include "base/cxx17_backports.h"
#include "base/numerics/safe_math.h" #include "base/numerics/safe_math.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -980,27 +980,27 @@ TEST(ProcessSnapshotMinidump, ThreadContextX86_64) {
minidump_context.fxsave.fpu_ip_64 = 42; minidump_context.fxsave.fpu_ip_64 = 42;
minidump_context.fxsave.fpu_dp_64 = 43; minidump_context.fxsave.fpu_dp_64 = 43;
for (size_t i = 0; i < base::size(minidump_context.vector_register); i++) { for (size_t i = 0; i < std::size(minidump_context.vector_register); i++) {
minidump_context.vector_register[i].lo = i * 2 + 44; minidump_context.vector_register[i].lo = i * 2 + 44;
minidump_context.vector_register[i].hi = i * 2 + 45; minidump_context.vector_register[i].hi = i * 2 + 45;
} }
for (uint8_t i = 0; i < base::size(minidump_context.fxsave.reserved_4); i++) { for (uint8_t i = 0; i < std::size(minidump_context.fxsave.reserved_4); i++) {
minidump_context.fxsave.reserved_4[i] = i * 2 + 115; minidump_context.fxsave.reserved_4[i] = i * 2 + 115;
minidump_context.fxsave.available[i] = i * 2 + 116; minidump_context.fxsave.available[i] = i * 2 + 116;
} }
for (size_t i = 0; i < base::size(minidump_context.fxsave.st_mm); i++) { for (size_t i = 0; i < std::size(minidump_context.fxsave.st_mm); i++) {
for (uint8_t j = 0; for (uint8_t j = 0;
j < base::size(minidump_context.fxsave.st_mm[0].mm_value); j < std::size(minidump_context.fxsave.st_mm[0].mm_value);
j++) { j++) {
minidump_context.fxsave.st_mm[i].mm_value[j] = j + 1; minidump_context.fxsave.st_mm[i].mm_value[j] = j + 1;
minidump_context.fxsave.st_mm[i].mm_reserved[j] = j + 1; minidump_context.fxsave.st_mm[i].mm_reserved[j] = j + 1;
} }
} }
for (size_t i = 0; i < base::size(minidump_context.fxsave.xmm); i++) { for (size_t i = 0; i < std::size(minidump_context.fxsave.xmm); i++) {
for (uint8_t j = 0; j < base::size(minidump_context.fxsave.xmm[0]); j++) { for (uint8_t j = 0; j < std::size(minidump_context.fxsave.xmm[0]); j++) {
minidump_context.fxsave.xmm[i][j] = j + 1; minidump_context.fxsave.xmm[i][j] = j + 1;
} }
} }
@ -1083,20 +1083,20 @@ TEST(ProcessSnapshotMinidump, ThreadContextX86_64) {
EXPECT_EQ(ctx->fxsave.fpu_ip_64, 42U); EXPECT_EQ(ctx->fxsave.fpu_ip_64, 42U);
EXPECT_EQ(ctx->fxsave.fpu_dp_64, 43U); EXPECT_EQ(ctx->fxsave.fpu_dp_64, 43U);
for (uint8_t i = 0; i < base::size(ctx->fxsave.reserved_4); i++) { for (uint8_t i = 0; i < std::size(ctx->fxsave.reserved_4); i++) {
EXPECT_EQ(ctx->fxsave.reserved_4[i], i * 2 + 115); EXPECT_EQ(ctx->fxsave.reserved_4[i], i * 2 + 115);
EXPECT_EQ(ctx->fxsave.available[i], i * 2 + 116); EXPECT_EQ(ctx->fxsave.available[i], i * 2 + 116);
} }
for (size_t i = 0; i < base::size(ctx->fxsave.st_mm); i++) { for (size_t i = 0; i < std::size(ctx->fxsave.st_mm); i++) {
for (uint8_t j = 0; j < base::size(ctx->fxsave.st_mm[0].mm_value); j++) { for (uint8_t j = 0; j < std::size(ctx->fxsave.st_mm[0].mm_value); j++) {
EXPECT_EQ(ctx->fxsave.st_mm[i].mm_value[j], j + 1); EXPECT_EQ(ctx->fxsave.st_mm[i].mm_value[j], j + 1);
EXPECT_EQ(ctx->fxsave.st_mm[i].mm_reserved[j], j + 1); EXPECT_EQ(ctx->fxsave.st_mm[i].mm_reserved[j], j + 1);
} }
} }
for (size_t i = 0; i < base::size(ctx->fxsave.xmm); i++) { for (size_t i = 0; i < std::size(ctx->fxsave.xmm); i++) {
for (uint8_t j = 0; j < base::size(ctx->fxsave.xmm[0]); j++) { for (uint8_t j = 0; j < std::size(ctx->fxsave.xmm[0]); j++) {
EXPECT_EQ(ctx->fxsave.xmm[i][j], j + 1); EXPECT_EQ(ctx->fxsave.xmm[i][j], j + 1);
} }
} }

View File

@ -17,8 +17,9 @@
#include <stddef.h> #include <stddef.h>
#include <time.h> #include <time.h>
#include <iterator>
#include "base/check.h" #include "base/check.h"
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "build/build_config.h" #include "build/build_config.h"
@ -61,8 +62,7 @@ void TimeZone(const timeval& snapshot_time,
static constexpr int kMonthDeltas[] = static constexpr int kMonthDeltas[] =
{0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, {0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6,
7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12}; 7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12};
for (size_t index = 0; for (size_t index = 0; index < std::size(kMonthDeltas) && !found_transition;
index < base::size(kMonthDeltas) && !found_transition;
++index) { ++index) {
// Look at a day of each month at local noon. Set tm_isdst to -1 to avoid // Look at a day of each month at local noon. Set tm_isdst to -1 to avoid
// giving mktime() any hints about whether to consider daylight saving // giving mktime() any hints about whether to consider daylight saving

View File

@ -18,9 +18,9 @@
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <iterator>
#include <string> #include <string>
#include "base/cxx17_backports.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "test/errors.h" #include "test/errors.h"
@ -154,7 +154,7 @@ TEST(TimeZone, Basic) {
{"UTC", false, 0, 0, "UTC", "UTC"}, {"UTC", false, 0, 0, "UTC", "UTC"},
}; };
for (size_t index = 0; index < base::size(kTestTimeZones); ++index) { for (size_t index = 0; index < std::size(kTestTimeZones); ++index) {
const auto& test_time_zone = kTestTimeZones[index]; const auto& test_time_zone = kTestTimeZones[index];
const char* tz = test_time_zone.tz; const char* tz = test_time_zone.tz;
SCOPED_TRACE(base::StringPrintf("index %zu, tz %s", index, tz)); SCOPED_TRACE(base::StringPrintf("index %zu, tz %s", index, tz));

View File

@ -16,7 +16,8 @@
#include <string.h> #include <string.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/notreached.h" #include "base/notreached.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -101,7 +102,7 @@ void ChildTestFunction() {
static StringAnnotation<32> non_allowed_annotation(kNonAllowedAnnotationName); static StringAnnotation<32> non_allowed_annotation(kNonAllowedAnnotationName);
non_allowed_annotation.Set(kNonAllowedAnnotationValue); non_allowed_annotation.Set(kNonAllowedAnnotationValue);
char string_data[base::size(kSensitiveStackData)]; char string_data[std::size(kSensitiveStackData)];
strcpy(string_data, kSensitiveStackData); strcpy(string_data, kSensitiveStackData);
void (*code_pointer)(void) = ChildTestFunction; void (*code_pointer)(void) = ChildTestFunction;

View File

@ -14,7 +14,8 @@
#include "snapshot/sanitized/sanitization_information.h" #include "snapshot/sanitized/sanitization_information.h"
#include "base/cxx17_backports.h" #include <iterator>
#include "build/build_config.h" #include "build/build_config.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "util/misc/from_pointer_cast.h" #include "util/misc/from_pointer_cast.h"
@ -66,7 +67,7 @@ const char* const kNonEmptyAllowedAnnotations[] = {"string1",
TEST_F(AllowedAnnotationsTest, NonEmptyAllowedAnnotations) { TEST_F(AllowedAnnotationsTest, NonEmptyAllowedAnnotations) {
ASSERT_TRUE(DoReadAllowedAnnotations(kNonEmptyAllowedAnnotations)); ASSERT_TRUE(DoReadAllowedAnnotations(kNonEmptyAllowedAnnotations));
ASSERT_EQ(allowed_annotations_.size(), ASSERT_EQ(allowed_annotations_.size(),
base::size(kNonEmptyAllowedAnnotations) - 1); std::size(kNonEmptyAllowedAnnotations) - 1);
for (size_t index = 0; index < allowed_annotations_.size(); ++index) { for (size_t index = 0; index < allowed_annotations_.size(); ++index) {
EXPECT_EQ(allowed_annotations_[index], kNonEmptyAllowedAnnotations[index]); EXPECT_EQ(allowed_annotations_[index], kNonEmptyAllowedAnnotations[index]);
} }

View File

@ -17,7 +17,7 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
namespace crashpad { namespace crashpad {
namespace test { namespace test {
@ -44,28 +44,28 @@ void InitializeCPUContextFxsave(FxsaveType* fxsave, uint32_t* seed) {
fxsave->reserved_3 = static_cast<uint16_t>(value++); fxsave->reserved_3 = static_cast<uint16_t>(value++);
fxsave->mxcsr = value++; fxsave->mxcsr = value++;
fxsave->mxcsr_mask = value++; fxsave->mxcsr_mask = value++;
for (size_t st_mm_index = 0; st_mm_index < base::size(fxsave->st_mm); for (size_t st_mm_index = 0; st_mm_index < std::size(fxsave->st_mm);
++st_mm_index) { ++st_mm_index) {
for (size_t byte = 0; byte < base::size(fxsave->st_mm[st_mm_index].st); for (size_t byte = 0; byte < std::size(fxsave->st_mm[st_mm_index].st);
++byte) { ++byte) {
fxsave->st_mm[st_mm_index].st[byte] = static_cast<uint8_t>(value++); fxsave->st_mm[st_mm_index].st[byte] = static_cast<uint8_t>(value++);
} }
for (size_t byte = 0; for (size_t byte = 0;
byte < base::size(fxsave->st_mm[st_mm_index].st_reserved); byte < std::size(fxsave->st_mm[st_mm_index].st_reserved);
++byte) { ++byte) {
fxsave->st_mm[st_mm_index].st_reserved[byte] = fxsave->st_mm[st_mm_index].st_reserved[byte] =
static_cast<uint8_t>(value); static_cast<uint8_t>(value);
} }
} }
for (size_t xmm_index = 0; xmm_index < base::size(fxsave->xmm); ++xmm_index) { for (size_t xmm_index = 0; xmm_index < std::size(fxsave->xmm); ++xmm_index) {
for (size_t byte = 0; byte < base::size(fxsave->xmm[xmm_index]); ++byte) { for (size_t byte = 0; byte < std::size(fxsave->xmm[xmm_index]); ++byte) {
fxsave->xmm[xmm_index][byte] = static_cast<uint8_t>(value++); fxsave->xmm[xmm_index][byte] = static_cast<uint8_t>(value++);
} }
} }
for (size_t byte = 0; byte < base::size(fxsave->reserved_4); ++byte) { for (size_t byte = 0; byte < std::size(fxsave->reserved_4); ++byte) {
fxsave->reserved_4[byte] = static_cast<uint8_t>(value++); fxsave->reserved_4[byte] = static_cast<uint8_t>(value++);
} }
for (size_t byte = 0; byte < base::size(fxsave->available); ++byte) { for (size_t byte = 0; byte < std::size(fxsave->available); ++byte) {
fxsave->available[byte] = static_cast<uint8_t>(value++); fxsave->available[byte] = static_cast<uint8_t>(value++);
} }
@ -174,7 +174,7 @@ void InitializeCPUContextARM(CPUContext* context, uint32_t seed) {
uint32_t value = seed; uint32_t value = seed;
for (size_t index = 0; index < base::size(arm->regs); ++index) { for (size_t index = 0; index < std::size(arm->regs); ++index) {
arm->regs[index] = value++; arm->regs[index] = value++;
} }
arm->fp = value++; arm->fp = value++;
@ -185,7 +185,7 @@ void InitializeCPUContextARM(CPUContext* context, uint32_t seed) {
arm->pc = value++; arm->pc = value++;
arm->cpsr = value++; arm->cpsr = value++;
for (size_t index = 0; index < base::size(arm->vfp_regs.vfp); ++index) { for (size_t index = 0; index < std::size(arm->vfp_regs.vfp); ++index) {
arm->vfp_regs.vfp[index] = value++; arm->vfp_regs.vfp[index] = value++;
} }
arm->vfp_regs.fpscr = value++; arm->vfp_regs.fpscr = value++;
@ -205,14 +205,14 @@ void InitializeCPUContextARM64(CPUContext* context, uint32_t seed) {
uint32_t value = seed; uint32_t value = seed;
for (size_t index = 0; index < base::size(arm64->regs); ++index) { for (size_t index = 0; index < std::size(arm64->regs); ++index) {
arm64->regs[index] = value++; arm64->regs[index] = value++;
} }
arm64->sp = value++; arm64->sp = value++;
arm64->pc = value++; arm64->pc = value++;
arm64->spsr = value++; arm64->spsr = value++;
for (size_t index = 0; index < base::size(arm64->fpsimd); ++index) { for (size_t index = 0; index < std::size(arm64->fpsimd); ++index) {
arm64->fpsimd[index].lo = value++; arm64->fpsimd[index].lo = value++;
arm64->fpsimd[index].hi = value++; arm64->fpsimd[index].hi = value++;
} }
@ -231,7 +231,7 @@ void InitializeCPUContextMIPS(CPUContext* context, uint32_t seed) {
uint32_t value = seed; uint32_t value = seed;
for (size_t index = 0; index < base::size(mipsel->regs); ++index) { for (size_t index = 0; index < std::size(mipsel->regs); ++index) {
mipsel->regs[index] = value++; mipsel->regs[index] = value++;
} }
@ -242,7 +242,7 @@ void InitializeCPUContextMIPS(CPUContext* context, uint32_t seed) {
mipsel->cp0_status = value++; mipsel->cp0_status = value++;
mipsel->cp0_cause = value++; mipsel->cp0_cause = value++;
for (size_t index = 0; index < base::size(mipsel->fpregs.fregs); ++index) { for (size_t index = 0; index < std::size(mipsel->fpregs.fregs); ++index) {
mipsel->fpregs.fregs[index]._fp_fregs = static_cast<float>(value++); mipsel->fpregs.fregs[index]._fp_fregs = static_cast<float>(value++);
} }
@ -267,7 +267,7 @@ void InitializeCPUContextMIPS64(CPUContext* context, uint32_t seed) {
uint64_t value = seed; uint64_t value = seed;
for (size_t index = 0; index < base::size(mips64->regs); ++index) { for (size_t index = 0; index < std::size(mips64->regs); ++index) {
mips64->regs[index] = value++; mips64->regs[index] = value++;
} }
@ -278,7 +278,7 @@ void InitializeCPUContextMIPS64(CPUContext* context, uint32_t seed) {
mips64->cp0_status = value++; mips64->cp0_status = value++;
mips64->cp0_cause = value++; mips64->cp0_cause = value++;
for (size_t index = 0; index < base::size(mips64->fpregs.dregs); ++index) { for (size_t index = 0; index < std::size(mips64->fpregs.dregs); ++index) {
mips64->fpregs.dregs[index] = static_cast<double>(value++); mips64->fpregs.dregs[index] = static_cast<double>(value++);
} }

View File

@ -16,7 +16,8 @@
#include <windows.h> #include <windows.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "build/build_config.h" #include "build/build_config.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "snapshot/cpu_context.h" #include "snapshot/cpu_context.h"
@ -87,13 +88,13 @@ void TestInitializeX86Context_FsaveWithoutFxsave() {
for (size_t st_mm = 0; st_mm < 7; ++st_mm) { for (size_t st_mm = 0; st_mm < 7; ++st_mm) {
EXPECT_EQ( EXPECT_EQ(
BytesToHexString(cpu_context_x86.fxsave.st_mm[st_mm].st, BytesToHexString(cpu_context_x86.fxsave.st_mm[st_mm].st,
base::size(cpu_context_x86.fxsave.st_mm[st_mm].st)), std::size(cpu_context_x86.fxsave.st_mm[st_mm].st)),
std::string(base::size(cpu_context_x86.fxsave.st_mm[st_mm].st) * 2, std::string(std::size(cpu_context_x86.fxsave.st_mm[st_mm].st) * 2,
'0')) '0'))
<< "st_mm " << st_mm; << "st_mm " << st_mm;
} }
EXPECT_EQ(BytesToHexString(cpu_context_x86.fxsave.st_mm[7].st, EXPECT_EQ(BytesToHexString(cpu_context_x86.fxsave.st_mm[7].st,
base::size(cpu_context_x86.fxsave.st_mm[7].st)), std::size(cpu_context_x86.fxsave.st_mm[7].st)),
"0000000000000080ff7f"); "0000000000000080ff7f");
EXPECT_EQ(cpu_context_x86.dr0, 3u); EXPECT_EQ(cpu_context_x86.dr0, 3u);

View File

@ -14,7 +14,8 @@
#include <windows.h> #include <windows.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/logging.h" #include "base/logging.h"
#include "client/crashpad_info.h" #include "client/crashpad_info.h"
#include "util/file/file_io.h" #include "util/file/file_io.h"
@ -29,7 +30,7 @@ DWORD WINAPI LotsOfReferencesThreadProc(void* param) {
// Allocate a bunch of pointers to things on the stack. // Allocate a bunch of pointers to things on the stack.
int* pointers[1000]; int* pointers[1000];
for (size_t i = 0; i < base::size(pointers); ++i) { for (size_t i = 0; i < std::size(pointers); ++i) {
pointers[i] = new int[2048]; pointers[i] = new int[2048];
} }
@ -53,7 +54,7 @@ int wmain(int argc, wchar_t* argv[]) {
// verify the cap on pointed-to memory. // verify the cap on pointed-to memory.
crashpad::Semaphore semaphore(0); crashpad::Semaphore semaphore(0);
crashpad::ScopedKernelHANDLE threads[100]; crashpad::ScopedKernelHANDLE threads[100];
for (size_t i = 0; i < base::size(threads); ++i) { for (size_t i = 0; i < std::size(threads); ++i) {
threads[i].reset(CreateThread(nullptr, threads[i].reset(CreateThread(nullptr,
0, 0,
&LotsOfReferencesThreadProc, &LotsOfReferencesThreadProc,
@ -66,7 +67,7 @@ int wmain(int argc, wchar_t* argv[]) {
} }
} }
for (size_t i = 0; i < base::size(threads); ++i) { for (size_t i = 0; i < std::size(threads); ++i) {
semaphore.Wait(); semaphore.Wait();
} }

View File

@ -17,7 +17,8 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "client/annotation.h" #include "client/annotation.h"
@ -157,8 +158,7 @@ void PEImageAnnotationsReader::ReadCrashpadAnnotationsList(
snapshot.type = current.type; snapshot.type = current.type;
char name[Annotation::kNameMaxLength]; char name[Annotation::kNameMaxLength];
if (!process_reader_->Memory()->Read( if (!process_reader_->Memory()->Read(current.name, std::size(name), name)) {
current.name, base::size(name), name)) {
LOG(WARNING) << "could not read annotation name at index " << index LOG(WARNING) << "could not read annotation name at index " << index
<< " in " << base::WideToUTF8(name_); << " in " << base::WideToUTF8(name_);
continue; continue;

View File

@ -18,9 +18,9 @@
#include <string.h> #include <string.h>
#include <algorithm> #include <algorithm>
#include <iterator>
#include <memory> #include <memory>
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "client/crashpad_info.h" #include "client/crashpad_info.h"
@ -288,7 +288,7 @@ bool PEImageReader::VSFixedFileInfo(
version_info.wType != 0 || version_info.wType != 0 ||
wcsncmp(version_info.szKey, wcsncmp(version_info.szKey,
L"VS_VERSION_INFO", L"VS_VERSION_INFO",
base::size(version_info.szKey)) != 0) { std::size(version_info.szKey)) != 0) {
LOG(WARNING) << "unexpected VS_VERSIONINFO in " LOG(WARNING) << "unexpected VS_VERSIONINFO in "
<< module_subrange_reader_.name(); << module_subrange_reader_.name();
return false; return false;

View File

@ -17,7 +17,8 @@
#include <windows.h> #include <windows.h>
#include <string.h> #include <string.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "test/win/win_multiprocess.h" #include "test/win/win_multiprocess.h"
#include "util/misc/from_pointer_cast.h" #include "util/misc/from_pointer_cast.h"
@ -44,7 +45,7 @@ TEST(ProcessReaderWin, SelfBasic) {
EXPECT_EQ(process_reader.GetProcessInfo().ProcessID(), GetCurrentProcessId()); EXPECT_EQ(process_reader.GetProcessInfo().ProcessID(), GetCurrentProcessId());
static constexpr char kTestMemory[] = "Some test memory"; static constexpr char kTestMemory[] = "Some test memory";
char buffer[base::size(kTestMemory)]; char buffer[std::size(kTestMemory)];
ASSERT_TRUE(process_reader.Memory()->Read( ASSERT_TRUE(process_reader.Memory()->Read(
reinterpret_cast<uintptr_t>(kTestMemory), sizeof(kTestMemory), &buffer)); reinterpret_cast<uintptr_t>(kTestMemory), sizeof(kTestMemory), &buffer));
EXPECT_STREQ(kTestMemory, buffer); EXPECT_STREQ(kTestMemory, buffer);
@ -193,7 +194,7 @@ class ProcessReaderChildThreadSuspendCount final : public WinMultiprocess {
// the pipe. // the pipe.
CheckedReadFileAtEOF(ReadPipeHandle()); CheckedReadFileAtEOF(ReadPipeHandle());
for (size_t i = 0; i < base::size(threads); ++i) for (size_t i = 0; i < std::size(threads); ++i)
done.Signal(); done.Signal();
for (auto& thread : threads) for (auto& thread : threads)
thread.Join(); thread.Join();

View File

@ -18,9 +18,9 @@
#include <wchar.h> #include <wchar.h>
#include <algorithm> #include <algorithm>
#include <iterator>
#include <utility> #include <utility>
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
@ -332,7 +332,7 @@ void ProcessSnapshotWin::InitializeUnloadedModules() {
uet.TimeDateStamp, uet.TimeDateStamp,
base::WideToUTF8(base::WStringPiece( base::WideToUTF8(base::WStringPiece(
uet.ImageName, uet.ImageName,
wcsnlen(uet.ImageName, base::size(uet.ImageName)))))); wcsnlen(uet.ImageName, std::size(uet.ImageName))))));
} }
} }
} }
@ -532,9 +532,9 @@ WinVMSize ProcessSnapshotWin::DetermineSizeOfEnvironmentBlock(
env_block.resize( env_block.resize(
static_cast<unsigned int>(bytes_read / sizeof(env_block[0]))); static_cast<unsigned int>(bytes_read / sizeof(env_block[0])));
static constexpr wchar_t terminator[] = {0, 0}; static constexpr wchar_t terminator[] = {0, 0};
size_t at = env_block.find(std::wstring(terminator, base::size(terminator))); size_t at = env_block.find(std::wstring(terminator, std::size(terminator)));
if (at != std::wstring::npos) if (at != std::wstring::npos)
env_block.resize(at + base::size(terminator)); env_block.resize(at + std::size(terminator));
return env_block.size() * sizeof(env_block[0]); return env_block.size() * sizeof(env_block[0]);
} }

View File

@ -29,8 +29,8 @@ namespace test {
//! uint8_t expected[10]; //! uint8_t expected[10];
//! uint8_t observed[10]; //! uint8_t observed[10];
//! // … //! // …
//! EXPECT_EQ(BytesToHexString(observed, base::size(observed)), //! EXPECT_EQ(BytesToHexString(observed, std::size(observed)),
//! BytesToHexString(expected, base::size(expected))); //! BytesToHexString(expected, std::size(expected)));
//! \endcode //! \endcode
std::string BytesToHexString(const void* bytes, size_t length); std::string BytesToHexString(const void* bytes, size_t length);

View File

@ -14,7 +14,8 @@
#include "test/hex_string.h" #include "test/hex_string.h"
#include "base/cxx17_backports.h" #include <iterator>
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace crashpad { namespace crashpad {
@ -25,7 +26,7 @@ TEST(HexString, HexString) {
EXPECT_EQ(BytesToHexString(nullptr, 0), ""); EXPECT_EQ(BytesToHexString(nullptr, 0), "");
static constexpr char kBytes[] = "Abc123xyz \x0a\x7f\xf0\x9f\x92\xa9_"; static constexpr char kBytes[] = "Abc123xyz \x0a\x7f\xf0\x9f\x92\xa9_";
EXPECT_EQ(BytesToHexString(kBytes, base::size(kBytes)), EXPECT_EQ(BytesToHexString(kBytes, std::size(kBytes)),
"41626331323378797a200a7ff09f92a95f00"); "41626331323378797a200a7ff09f92a95f00");
} }

View File

@ -21,13 +21,13 @@
#include <sys/types.h> #include <sys/types.h>
#include <time.h> #include <time.h>
#include <iterator>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "base/check_op.h" #include "base/check_op.h"
#include "base/cxx17_backports.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
@ -111,14 +111,14 @@ bool StringToBool(const char* string, bool* boolean) {
"set", "set",
}; };
for (size_t index = 0; index < base::size(kFalseWords); ++index) { for (size_t index = 0; index < std::size(kFalseWords); ++index) {
if (strcasecmp(string, kFalseWords[index]) == 0) { if (strcasecmp(string, kFalseWords[index]) == 0) {
*boolean = false; *boolean = false;
return true; return true;
} }
} }
for (size_t index = 0; index < base::size(kTrueWords); ++index) { for (size_t index = 0; index < std::size(kTrueWords); ++index) {
if (strcasecmp(string, kTrueWords[index]) == 0) { if (strcasecmp(string, kTrueWords[index]) == 0) {
*boolean = true; *boolean = true;
return true; return true;
@ -161,7 +161,7 @@ bool StringToTime(const char* string, time_t* out_time, bool utc) {
"%+", "%+",
}; };
for (size_t index = 0; index < base::size(kFormats); ++index) { for (size_t index = 0; index < std::size(kFormats); ++index) {
tm time_tm; tm time_tm;
const char* strptime_result = strptime(string, kFormats[index], &time_tm); const char* strptime_result = strptime(string, kFormats[index], &time_tm);
if (strptime_result == end) { if (strptime_result == end) {
@ -216,7 +216,7 @@ std::string TimeToString(time_t out_time, bool utc) {
char string[64]; char string[64];
CHECK_NE( CHECK_NE(
strftime(string, base::size(string), "%Y-%m-%d %H:%M:%S %Z", &time_tm), strftime(string, std::size(string), "%Y-%m-%d %H:%M:%S %Z", &time_tm),
0u); 0u);
return std::string(string); return std::string(string);

View File

@ -17,10 +17,10 @@
#include <sys/types.h> #include <sys/types.h>
#include <algorithm> #include <algorithm>
#include <iterator>
#include <limits> #include <limits>
#include "base/check_op.h" #include "base/check_op.h"
#include "base/cxx17_backports.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
namespace crashpad { namespace crashpad {
@ -76,7 +76,7 @@ DelimitedFileReader::Result DelimitedFileReader::GetDelim(char delimiter,
return Result::kEndOfFile; return Result::kEndOfFile;
} }
DCHECK_LE(static_cast<size_t>(read_result), base::size(buf_)); DCHECK_LE(static_cast<size_t>(read_result), std::size(buf_));
DCHECK( DCHECK(
base::IsValueInRangeForNumericType<decltype(buf_len_)>(read_result)); base::IsValueInRangeForNumericType<decltype(buf_len_)>(read_result));
buf_len_ = static_cast<decltype(buf_len_)>(read_result); buf_len_ = static_cast<decltype(buf_len_)>(read_result);

View File

@ -14,9 +14,9 @@
#include "util/file/delimited_file_reader.h" #include "util/file/delimited_file_reader.h"
#include <iterator>
#include <vector> #include <vector>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -260,7 +260,7 @@ TEST(DelimitedFileReader, ReallyLongMultiLineFile) {
TEST(DelimitedFileReader, EmbeddedNUL) { TEST(DelimitedFileReader, EmbeddedNUL) {
static constexpr char kString[] = "embedded\0NUL\n"; static constexpr char kString[] = "embedded\0NUL\n";
StringFile string_file; StringFile string_file;
string_file.SetString(std::string(kString, base::size(kString) - 1)); string_file.SetString(std::string(kString, std::size(kString) - 1));
DelimitedFileReader delimited_file_reader(&string_file); DelimitedFileReader delimited_file_reader(&string_file);
std::string line; std::string line;
@ -278,7 +278,7 @@ TEST(DelimitedFileReader, EmbeddedNUL) {
TEST(DelimitedFileReader, NULDelimiter) { TEST(DelimitedFileReader, NULDelimiter) {
static constexpr char kString[] = "aa\0b\0ccc\0"; static constexpr char kString[] = "aa\0b\0ccc\0";
StringFile string_file; StringFile string_file;
string_file.SetString(std::string(kString, base::size(kString) - 1)); string_file.SetString(std::string(kString, std::size(kString) - 1));
DelimitedFileReader delimited_file_reader(&string_file); DelimitedFileReader delimited_file_reader(&string_file);
std::string field; std::string field;
@ -302,7 +302,7 @@ TEST(DelimitedFileReader, NULDelimiter) {
TEST(DelimitedFileReader, EdgeCases) { TEST(DelimitedFileReader, EdgeCases) {
static constexpr size_t kSizes[] = static constexpr size_t kSizes[] =
{4094, 4095, 4096, 4097, 8190, 8191, 8192, 8193}; {4094, 4095, 4096, 4097, 8190, 8191, 8192, 8193};
for (size_t index = 0; index < base::size(kSizes); ++index) { for (size_t index = 0; index < std::size(kSizes); ++index) {
size_t size = kSizes[index]; size_t size = kSizes[index];
SCOPED_TRACE( SCOPED_TRACE(
base::StringPrintf("index %" PRIuS ", size %" PRIuS, index, size)); base::StringPrintf("index %" PRIuS ", size %" PRIuS, index, size));

View File

@ -16,11 +16,11 @@
#include <stdio.h> #include <stdio.h>
#include <iterator>
#include <limits> #include <limits>
#include <type_traits> #include <type_traits>
#include "base/atomicops.h" #include "base/atomicops.h"
#include "base/cxx17_backports.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gmock/gmock.h" #include "gmock/gmock.h"
@ -643,7 +643,7 @@ void LockingTest(FileLocking main_lock, FileLocking other_locks) {
LockingTestThread threads[20]; LockingTestThread threads[20];
int expected_iterations = 0; int expected_iterations = 0;
for (size_t index = 0; index < base::size(threads); ++index) { for (size_t index = 0; index < std::size(threads); ++index) {
int iterations_for_this_thread = static_cast<int>(index * 10); int iterations_for_this_thread = static_cast<int>(index * 10);
threads[index].Init( threads[index].Init(
(other_locks == FileLocking::kShared) (other_locks == FileLocking::kShared)

View File

@ -18,7 +18,8 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h" #include "base/logging.h"
#include "util/file/file_io.h" #include "util/file/file_io.h"
@ -48,7 +49,7 @@ bool ProcStatReader::Initialize(PtraceConnection* connection, pid_t tid) {
INITIALIZATION_STATE_SET_INITIALIZING(initialized_); INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
char path[32]; char path[32];
snprintf(path, base::size(path), "/proc/%d/stat", tid); snprintf(path, std::size(path), "/proc/%d/stat", tid);
if (!connection->ReadFileContents(base::FilePath(path), &contents_)) { if (!connection->ReadFileContents(base::FilePath(path), &contents_)) {
return false; return false;
} }

View File

@ -16,7 +16,8 @@
#include <stdio.h> #include <stdio.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
@ -29,7 +30,7 @@ bool ReadThreadIDs(pid_t pid, std::vector<pid_t>* tids) {
DCHECK(tids->empty()); DCHECK(tids->empty());
char path[32]; char path[32];
snprintf(path, base::size(path), "/proc/%d/task", pid); snprintf(path, std::size(path), "/proc/%d/task", pid);
DirectoryReader reader; DirectoryReader reader;
if (!reader.Open(base::FilePath(path))) { if (!reader.Open(base::FilePath(path))) {
return false; return false;

View File

@ -18,9 +18,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <iterator>
#include <string> #include <string>
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "util/file/file_io.h" #include "util/file/file_io.h"
@ -265,7 +265,7 @@ bool PtraceClient::Threads(std::vector<pid_t>* threads) {
threads->push_back(pid_); threads->push_back(pid_);
char path[32]; char path[32];
snprintf(path, base::size(path), "/proc/%d/task", pid_); snprintf(path, std::size(path), "/proc/%d/task", pid_);
PtraceBroker::Request request = {}; PtraceBroker::Request request = {};
request.type = PtraceBroker::Request::kTypeListDirectory; request.type = PtraceBroker::Request::kTypeListDirectory;

View File

@ -17,9 +17,9 @@
#include <mach/mach.h> #include <mach/mach.h>
#include <sys/types.h> #include <sys/types.h>
#include <iterator>
#include <limits> #include <limits>
#include "base/cxx17_backports.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -116,7 +116,7 @@ TEST(CheckedMachAddressRange, IsValid) {
{0xffffffffffffffff, 1, kInvalid}, {0xffffffffffffffff, 1, kInvalid},
}; };
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %zu, base 0x%llx, size 0x%llx", SCOPED_TRACE(base::StringPrintf("index %zu, base 0x%llx, size 0x%llx",
index, index,
@ -166,7 +166,7 @@ TEST(CheckedMachAddressRange, ContainsValue) {
CheckedMachAddressRange parent_range_32(false, 0x2000, 0x1000); CheckedMachAddressRange parent_range_32(false, 0x2000, 0x1000);
ASSERT_TRUE(parent_range_32.IsValid()); ASSERT_TRUE(parent_range_32.IsValid());
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE( SCOPED_TRACE(
base::StringPrintf("index %zu, value 0x%llx", index, testcase.value)); base::StringPrintf("index %zu, value 0x%llx", index, testcase.value));
@ -223,7 +223,7 @@ TEST(CheckedMachAddressRange, ContainsRange) {
CheckedMachAddressRange parent_range_32(false, 0x2000, 0x1000); CheckedMachAddressRange parent_range_32(false, 0x2000, 0x1000);
ASSERT_TRUE(parent_range_32.IsValid()); ASSERT_TRUE(parent_range_32.IsValid());
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %zu, base 0x%llx, size 0x%llx", SCOPED_TRACE(base::StringPrintf("index %zu, base 0x%llx, size 0x%llx",
index, index,

View File

@ -20,9 +20,9 @@
#include <string.h> #include <string.h>
#include <cmath> #include <cmath>
#include <iterator>
#include <limits> #include <limits>
#include "base/cxx17_backports.h"
#include "base/mac/scoped_launch_data.h" #include "base/mac/scoped_launch_data.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "util/stdlib/objc.h" #include "util/stdlib/objc.h"
@ -58,7 +58,7 @@ TEST(Launchd, CFPropertyToLaunchData_Integer) {
@0xfedcba9876543210, @0xfedcba9876543210,
}; };
for (size_t index = 0; index < base::size(integer_nses); ++index) { for (size_t index = 0; index < std::size(integer_nses); ++index) {
NSNumber* integer_ns = integer_nses[index]; NSNumber* integer_ns = integer_nses[index];
launch_data.reset(CFPropertyToLaunchData(integer_ns)); launch_data.reset(CFPropertyToLaunchData(integer_ns));
ASSERT_TRUE(launch_data.get()); ASSERT_TRUE(launch_data.get());
@ -88,7 +88,7 @@ TEST(Launchd, CFPropertyToLaunchData_FloatingPoint) {
@(std::numeric_limits<double>::signaling_NaN()), @(std::numeric_limits<double>::signaling_NaN()),
}; };
for (size_t index = 0; index < base::size(double_nses); ++index) { for (size_t index = 0; index < std::size(double_nses); ++index) {
NSNumber* double_ns = double_nses[index]; NSNumber* double_ns = double_nses[index];
launch_data.reset(CFPropertyToLaunchData(double_ns)); launch_data.reset(CFPropertyToLaunchData(double_ns));
ASSERT_TRUE(launch_data.get()); ASSERT_TRUE(launch_data.get());
@ -114,7 +114,7 @@ TEST(Launchd, CFPropertyToLaunchData_Boolean) {
@YES, @YES,
}; };
for (size_t index = 0; index < base::size(bool_nses); ++index) { for (size_t index = 0; index < std::size(bool_nses); ++index) {
NSNumber* bool_ns = bool_nses[index]; NSNumber* bool_ns = bool_nses[index];
launch_data.reset(CFPropertyToLaunchData(bool_ns)); launch_data.reset(CFPropertyToLaunchData(bool_ns));
ASSERT_TRUE(launch_data.get()); ASSERT_TRUE(launch_data.get());
@ -138,7 +138,7 @@ TEST(Launchd, CFPropertyToLaunchData_String) {
@"Üñîçø∂é", @"Üñîçø∂é",
}; };
for (size_t index = 0; index < base::size(string_nses); ++index) { for (size_t index = 0; index < std::size(string_nses); ++index) {
NSString* string_ns = string_nses[index]; NSString* string_ns = string_nses[index];
launch_data.reset(CFPropertyToLaunchData(string_ns)); launch_data.reset(CFPropertyToLaunchData(string_ns));
ASSERT_TRUE(launch_data.get()); ASSERT_TRUE(launch_data.get());

View File

@ -24,10 +24,10 @@
#include <unistd.h> #include <unistd.h>
#include <algorithm> #include <algorithm>
#include <iterator>
#include <utility> #include <utility>
#include "base/check_op.h" #include "base/check_op.h"
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/mach_logging.h" #include "base/mac/mach_logging.h"
#include "base/mac/scoped_mach_port.h" #include "base/mac/scoped_mach_port.h"
@ -167,8 +167,8 @@ mach_port_t ChildPortHandshakeServer::RunServer(
0, 0,
0, 0,
nullptr); nullptr);
int rv = HANDLE_EINTR(kevent( int rv = HANDLE_EINTR(
kq.get(), changelist, base::size(changelist), nullptr, 0, nullptr)); kevent(kq.get(), changelist, std::size(changelist), nullptr, 0, nullptr));
PCHECK(rv != -1) << "kevent"; PCHECK(rv != -1) << "kevent";
ChildPortServer child_port_server(this); ChildPortServer child_port_server(this);

View File

@ -14,7 +14,8 @@
#include "util/mach/child_port_server.h" #include "util/mach/child_port_server.h"
#include "base/cxx17_backports.h" #include <iterator>
#include "util/mach/child_portServer.h" #include "util/mach/child_portServer.h"
#include "util/mach/mach_message.h" #include "util/mach/mach_message.h"
@ -90,7 +91,7 @@ std::set<mach_msg_id_t> ChildPortServer::MachMessageServerRequestIDs() {
static constexpr mach_msg_id_t request_ids[] = static constexpr mach_msg_id_t request_ids[] =
{kMachMessageIDChildPortCheckIn}; {kMachMessageIDChildPortCheckIn};
return std::set<mach_msg_id_t>(&request_ids[0], return std::set<mach_msg_id_t>(&request_ids[0],
&request_ids[base::size(request_ids)]); &request_ids[std::size(request_ids)]);
} }
mach_msg_size_t ChildPortServer::MachMessageServerRequestSize() { mach_msg_size_t ChildPortServer::MachMessageServerRequestSize() {

View File

@ -16,7 +16,8 @@
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "test/gtest_death.h" #include "test/gtest_death.h"
@ -198,7 +199,7 @@ TEST(CompositeMachMessageServer, ThreeHandlers) {
TestMachMessageHandler handlers[3]; TestMachMessageHandler handlers[3];
std::set<mach_msg_id_t> expect_request_ids; std::set<mach_msg_id_t> expect_request_ids;
for (size_t index = 0; index < base::size(kRequestIDs0); ++index) { for (size_t index = 0; index < std::size(kRequestIDs0); ++index) {
const mach_msg_id_t request_id = kRequestIDs0[index]; const mach_msg_id_t request_id = kRequestIDs0[index];
handlers[0].AddRequestID(request_id); handlers[0].AddRequestID(request_id);
expect_request_ids.insert(request_id); expect_request_ids.insert(request_id);
@ -207,7 +208,7 @@ TEST(CompositeMachMessageServer, ThreeHandlers) {
handlers[0].SetReplySize(sizeof(mig_reply_error_t)); handlers[0].SetReplySize(sizeof(mig_reply_error_t));
handlers[0].SetReturnCodes(true, kReturnCode0, false); handlers[0].SetReturnCodes(true, kReturnCode0, false);
for (size_t index = 0; index < base::size(kRequestIDs1); ++index) { for (size_t index = 0; index < std::size(kRequestIDs1); ++index) {
const mach_msg_id_t request_id = kRequestIDs1[index]; const mach_msg_id_t request_id = kRequestIDs1[index];
handlers[1].AddRequestID(request_id); handlers[1].AddRequestID(request_id);
expect_request_ids.insert(request_id); expect_request_ids.insert(request_id);
@ -216,7 +217,7 @@ TEST(CompositeMachMessageServer, ThreeHandlers) {
handlers[1].SetReplySize(200); handlers[1].SetReplySize(200);
handlers[1].SetReturnCodes(false, kReturnCode1, true); handlers[1].SetReturnCodes(false, kReturnCode1, true);
for (size_t index = 0; index < base::size(kRequestIDs2); ++index) { for (size_t index = 0; index < std::size(kRequestIDs2); ++index) {
const mach_msg_id_t request_id = kRequestIDs2[index]; const mach_msg_id_t request_id = kRequestIDs2[index];
handlers[2].AddRequestID(request_id); handlers[2].AddRequestID(request_id);
expect_request_ids.insert(request_id); expect_request_ids.insert(request_id);
@ -254,7 +255,7 @@ TEST(CompositeMachMessageServer, ThreeHandlers) {
// Send messages with known request IDs. // Send messages with known request IDs.
for (size_t index = 0; index < base::size(kRequestIDs0); ++index) { for (size_t index = 0; index < std::size(kRequestIDs0); ++index) {
request.header.msgh_id = kRequestIDs0[index]; request.header.msgh_id = kRequestIDs0[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"handler 0, index %zu, id %d", index, request.header.msgh_id)); "handler 0, index %zu, id %d", index, request.header.msgh_id));
@ -265,7 +266,7 @@ TEST(CompositeMachMessageServer, ThreeHandlers) {
EXPECT_FALSE(destroy_complex_request); EXPECT_FALSE(destroy_complex_request);
} }
for (size_t index = 0; index < base::size(kRequestIDs1); ++index) { for (size_t index = 0; index < std::size(kRequestIDs1); ++index) {
request.header.msgh_id = kRequestIDs1[index]; request.header.msgh_id = kRequestIDs1[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"handler 1, index %zu, id %d", index, request.header.msgh_id)); "handler 1, index %zu, id %d", index, request.header.msgh_id));
@ -276,7 +277,7 @@ TEST(CompositeMachMessageServer, ThreeHandlers) {
EXPECT_TRUE(destroy_complex_request); EXPECT_TRUE(destroy_complex_request);
} }
for (size_t index = 0; index < base::size(kRequestIDs2); ++index) { for (size_t index = 0; index < std::size(kRequestIDs2); ++index) {
request.header.msgh_id = kRequestIDs2[index]; request.header.msgh_id = kRequestIDs2[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"handler 2, index %zu, id %d", index, request.header.msgh_id)); "handler 2, index %zu, id %d", index, request.header.msgh_id));

View File

@ -19,7 +19,8 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "test/mac/mach_errors.h" #include "test/mac/mach_errors.h"
@ -184,11 +185,11 @@ class TestExcClientVariants : public MachMultiprocess,
// These arent real flavors, its just for testing. // These arent real flavors, its just for testing.
flavor = exception_ + 10; flavor = exception_ + 10;
flavor_p = &flavor; flavor_p = &flavor;
for (size_t index = 0; index < base::size(old_state); ++index) { for (size_t index = 0; index < std::size(old_state); ++index) {
old_state[index] = index; old_state[index] = index;
} }
old_state_p = reinterpret_cast<thread_state_t>(&old_state); old_state_p = reinterpret_cast<thread_state_t>(&old_state);
old_state_count = base::size(old_state); old_state_count = std::size(old_state);
// new_state and new_state_count are out parameters that the server should // new_state and new_state_count are out parameters that the server should
// never see or use, so set them to bogus values. The call to the server // never see or use, so set them to bogus values. The call to the server
@ -205,7 +206,7 @@ class TestExcClientVariants : public MachMultiprocess,
task, task,
exception, exception,
code, code,
base::size(code), std::size(code),
flavor_p, flavor_p,
old_state_p, old_state_p,
old_state_count, old_state_count,
@ -274,7 +275,7 @@ TEST(ExcClientVariants, UniversalExceptionRaise) {
kMachExceptionCodes | EXCEPTION_STATE_IDENTITY, kMachExceptionCodes | EXCEPTION_STATE_IDENTITY,
}; };
for (size_t index = 0; index < base::size(kBehaviors); ++index) { for (size_t index = 0; index < std::size(kBehaviors); ++index) {
exception_behavior_t behavior = kBehaviors[index]; exception_behavior_t behavior = kBehaviors[index];
SCOPED_TRACE(base::StringPrintf("index %zu, behavior %d", index, behavior)); SCOPED_TRACE(base::StringPrintf("index %zu, behavior %d", index, behavior));

View File

@ -18,9 +18,9 @@
#include <string.h> #include <string.h>
#include <algorithm> #include <algorithm>
#include <iterator>
#include <vector> #include <vector>
#include "base/cxx17_backports.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "util/mac/mac_util.h" #include "util/mac/mac_util.h"
#include "util/mach/composite_mach_message_server.h" #include "util/mach/composite_mach_message_server.h"
@ -246,7 +246,7 @@ class ExcServer : public MachMessageServer::Interface {
Traits::kMachMessageIDExceptionRaiseStateIdentity, Traits::kMachMessageIDExceptionRaiseStateIdentity,
}; };
return std::set<mach_msg_id_t>(&request_ids[0], return std::set<mach_msg_id_t>(&request_ids[0],
&request_ids[base::size(request_ids)]); &request_ids[std::size(request_ids)]);
} }
mach_msg_size_t MachMessageServerRequestSize() override { mach_msg_size_t MachMessageServerRequestSize() override {
@ -321,7 +321,7 @@ bool ExcServer<Traits>::MachMessageServerFunction(
using Reply = typename Traits::ExceptionRaiseStateReply; using Reply = typename Traits::ExceptionRaiseStateReply;
Reply* out_reply = reinterpret_cast<Reply*>(out_header); Reply* out_reply = reinterpret_cast<Reply*>(out_header);
out_reply->flavor = in_request_1->flavor; out_reply->flavor = in_request_1->flavor;
out_reply->new_stateCnt = base::size(out_reply->new_state); out_reply->new_stateCnt = std::size(out_reply->new_state);
out_reply->RetCode = out_reply->RetCode =
interface_->CatchExceptionRaiseState(in_header->msgh_local_port, interface_->CatchExceptionRaiseState(in_header->msgh_local_port,
in_request->exception, in_request->exception,
@ -364,7 +364,7 @@ bool ExcServer<Traits>::MachMessageServerFunction(
using Reply = typename Traits::ExceptionRaiseStateIdentityReply; using Reply = typename Traits::ExceptionRaiseStateIdentityReply;
Reply* out_reply = reinterpret_cast<Reply*>(out_header); Reply* out_reply = reinterpret_cast<Reply*>(out_header);
out_reply->flavor = in_request_1->flavor; out_reply->flavor = in_request_1->flavor;
out_reply->new_stateCnt = base::size(out_reply->new_state); out_reply->new_stateCnt = std::size(out_reply->new_state);
out_reply->RetCode = interface_->CatchExceptionRaiseStateIdentity( out_reply->RetCode = interface_->CatchExceptionRaiseStateIdentity(
in_header->msgh_local_port, in_header->msgh_local_port,
in_request->thread.name, in_request->thread.name,

View File

@ -19,7 +19,8 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gmock/gmock.h" #include "gmock/gmock.h"
@ -232,7 +233,7 @@ struct __attribute__((packed, aligned(4))) ExceptionRaiseStateReply {
EXPECT_EQ(memcmp(&NDR, &NDR_record, sizeof(NDR)), 0); EXPECT_EQ(memcmp(&NDR, &NDR_record, sizeof(NDR)), 0);
EXPECT_EQ(RetCode, KERN_SUCCESS); EXPECT_EQ(RetCode, KERN_SUCCESS);
EXPECT_EQ(flavor, kThreadStateFlavor); EXPECT_EQ(flavor, kThreadStateFlavor);
EXPECT_EQ(new_stateCnt, base::size(new_state)); EXPECT_EQ(new_stateCnt, std::size(new_state));
} }
mach_msg_header_t Head; mach_msg_header_t Head;
@ -664,7 +665,7 @@ TEST(ExcServerVariants, MockExceptionRaiseState) {
AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]), AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]),
Pointee(Eq(kThreadStateFlavor)), Pointee(Eq(kThreadStateFlavor)),
IsThreadStateAndCount(kThreadStateFlavorCount), IsThreadStateAndCount(kThreadStateFlavorCount),
IsThreadStateAndCount(base::size(reply.new_state)), IsThreadStateAndCount(std::size(reply.new_state)),
Eq(request.Trailer()))) Eq(request.Trailer())))
.WillOnce(Return(KERN_SUCCESS)) .WillOnce(Return(KERN_SUCCESS))
.RetiresOnSaturation(); .RetiresOnSaturation();
@ -713,7 +714,7 @@ TEST(ExcServerVariants, MockExceptionRaiseStateIdentity) {
AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]), AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]),
Pointee(Eq(kThreadStateFlavor)), Pointee(Eq(kThreadStateFlavor)),
IsThreadStateAndCount(kThreadStateFlavorCount), IsThreadStateAndCount(kThreadStateFlavorCount),
IsThreadStateAndCount(base::size(reply.new_state)), IsThreadStateAndCount(std::size(reply.new_state)),
Eq(request.Trailer()))) Eq(request.Trailer())))
.WillOnce(Return(KERN_SUCCESS)) .WillOnce(Return(KERN_SUCCESS))
.RetiresOnSaturation(); .RetiresOnSaturation();
@ -807,7 +808,7 @@ TEST(ExcServerVariants, MockMachExceptionRaiseState) {
kTestMachExceptionCodes[1]), kTestMachExceptionCodes[1]),
Pointee(Eq(kThreadStateFlavor)), Pointee(Eq(kThreadStateFlavor)),
IsThreadStateAndCount(kThreadStateFlavorCount), IsThreadStateAndCount(kThreadStateFlavorCount),
IsThreadStateAndCount(base::size(reply.new_state)), IsThreadStateAndCount(std::size(reply.new_state)),
Eq(request.Trailer()))) Eq(request.Trailer())))
.WillOnce(Return(KERN_SUCCESS)) .WillOnce(Return(KERN_SUCCESS))
.RetiresOnSaturation(); .RetiresOnSaturation();
@ -857,7 +858,7 @@ TEST(ExcServerVariants, MockMachExceptionRaiseStateIdentity) {
kTestMachExceptionCodes[1]), kTestMachExceptionCodes[1]),
Pointee(Eq(kThreadStateFlavor)), Pointee(Eq(kThreadStateFlavor)),
IsThreadStateAndCount(kThreadStateFlavorCount), IsThreadStateAndCount(kThreadStateFlavorCount),
IsThreadStateAndCount(base::size(reply.new_state)), IsThreadStateAndCount(std::size(reply.new_state)),
Eq(request.Trailer()))) Eq(request.Trailer())))
.WillOnce(Return(KERN_SUCCESS)) .WillOnce(Return(KERN_SUCCESS))
.RetiresOnSaturation(); .RetiresOnSaturation();
@ -911,7 +912,7 @@ TEST(ExcServerVariants, MockUnknownID) {
2508, 2508,
}; };
for (size_t index = 0; index < base::size(unknown_ids); ++index) { for (size_t index = 0; index < std::size(unknown_ids); ++index) {
mach_msg_id_t id = unknown_ids[index]; mach_msg_id_t id = unknown_ids[index];
SCOPED_TRACE(base::StringPrintf("unknown id %d", id)); SCOPED_TRACE(base::StringPrintf("unknown id %d", id));
@ -1190,7 +1191,7 @@ TEST(ExcServerVariants, ThreadStates) {
#endif #endif
}; };
for (size_t index = 0; index < base::size(test_data); ++index) { for (size_t index = 0; index < std::size(test_data); ++index) {
const auto& test = test_data[index]; const auto& test = test_data[index];
SCOPED_TRACE( SCOPED_TRACE(
base::StringPrintf("index %zu, flavor %d", index, test.flavor)); base::StringPrintf("index %zu, flavor %d", index, test.flavor));
@ -1270,7 +1271,7 @@ TEST(ExcServerVariants, ExcServerSuccessfulReturnValue) {
KERN_SUCCESS}, KERN_SUCCESS},
}; };
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto& test_data = kTestData[index]; const auto& test_data = kTestData[index];
SCOPED_TRACE( SCOPED_TRACE(
base::StringPrintf("index %zu, behavior %d, set_thread_state %s", base::StringPrintf("index %zu, behavior %d, set_thread_state %s",
@ -1289,8 +1290,8 @@ TEST(ExcServerVariants, ExcServerCopyState) {
static constexpr natural_t old_state[] = {1, 2, 3, 4, 5}; static constexpr natural_t old_state[] = {1, 2, 3, 4, 5};
natural_t new_state[10] = {}; natural_t new_state[10] = {};
constexpr mach_msg_type_number_t old_state_count = base::size(old_state); constexpr mach_msg_type_number_t old_state_count = std::size(old_state);
mach_msg_type_number_t new_state_count = base::size(new_state); mach_msg_type_number_t new_state_count = std::size(new_state);
// EXCEPTION_DEFAULT (with or without MACH_EXCEPTION_CODES) is not // EXCEPTION_DEFAULT (with or without MACH_EXCEPTION_CODES) is not
// state-carrying. new_state and new_state_count should be untouched. // state-carrying. new_state and new_state_count should be untouched.
@ -1299,8 +1300,8 @@ TEST(ExcServerVariants, ExcServerCopyState) {
old_state_count, old_state_count,
new_state, new_state,
&new_state_count); &new_state_count);
EXPECT_EQ(new_state_count, base::size(new_state)); EXPECT_EQ(new_state_count, std::size(new_state));
for (size_t i = 0; i < base::size(new_state); ++i) { for (size_t i = 0; i < std::size(new_state); ++i) {
EXPECT_EQ(new_state[i], 0u) << "i " << i; EXPECT_EQ(new_state[i], 0u) << "i " << i;
} }
@ -1309,8 +1310,8 @@ TEST(ExcServerVariants, ExcServerCopyState) {
old_state_count, old_state_count,
new_state, new_state,
&new_state_count); &new_state_count);
EXPECT_EQ(new_state_count, base::size(new_state)); EXPECT_EQ(new_state_count, std::size(new_state));
for (size_t i = 0; i < base::size(new_state); ++i) { for (size_t i = 0; i < std::size(new_state); ++i) {
EXPECT_EQ(new_state[i], 0u) << "i " << i; EXPECT_EQ(new_state[i], 0u) << "i " << i;
} }
@ -1322,7 +1323,7 @@ TEST(ExcServerVariants, ExcServerCopyState) {
for (size_t i = 0; i < copy_limit; ++i) { for (size_t i = 0; i < copy_limit; ++i) {
EXPECT_EQ(new_state[i], old_state[i]) << "i " << i; EXPECT_EQ(new_state[i], old_state[i]) << "i " << i;
} }
for (size_t i = copy_limit; i < base::size(new_state); ++i) { for (size_t i = copy_limit; i < std::size(new_state); ++i) {
EXPECT_EQ(new_state[i], 0u) << "i " << i; EXPECT_EQ(new_state[i], 0u) << "i " << i;
} }
@ -1338,23 +1339,23 @@ TEST(ExcServerVariants, ExcServerCopyState) {
for (size_t i = 0; i < copy_limit; ++i) { for (size_t i = 0; i < copy_limit; ++i) {
EXPECT_EQ(new_state[i], old_state[i]) << "i " << i; EXPECT_EQ(new_state[i], old_state[i]) << "i " << i;
} }
for (size_t i = copy_limit; i < base::size(new_state); ++i) { for (size_t i = copy_limit; i < std::size(new_state); ++i) {
EXPECT_EQ(new_state[i], 0u) << "i " << i; EXPECT_EQ(new_state[i], 0u) << "i " << i;
} }
// This is a state-carrying exception where all of old_state is copied to // This is a state-carrying exception where all of old_state is copied to
// new_state, which is large enough to receive it and then some. // new_state, which is large enough to receive it and then some.
new_state_count = base::size(new_state); new_state_count = std::size(new_state);
ExcServerCopyState(MACH_EXCEPTION_CODES | EXCEPTION_STATE_IDENTITY, ExcServerCopyState(MACH_EXCEPTION_CODES | EXCEPTION_STATE_IDENTITY,
old_state, old_state,
old_state_count, old_state_count,
new_state, new_state,
&new_state_count); &new_state_count);
EXPECT_EQ(new_state_count, old_state_count); EXPECT_EQ(new_state_count, old_state_count);
for (size_t i = 0; i < base::size(old_state); ++i) { for (size_t i = 0; i < std::size(old_state); ++i) {
EXPECT_EQ(new_state[i], old_state[i]) << "i " << i; EXPECT_EQ(new_state[i], old_state[i]) << "i " << i;
} }
for (size_t i = base::size(old_state); i < base::size(new_state); ++i) { for (size_t i = std::size(old_state); i < std::size(new_state); ++i) {
EXPECT_EQ(new_state[i], 0u) << "i " << i; EXPECT_EQ(new_state[i], 0u) << "i " << i;
} }
} }

View File

@ -16,7 +16,8 @@
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "util/mach/mach_extensions.h" #include "util/mach/mach_extensions.h"
@ -53,7 +54,7 @@ TEST(ExceptionBehaviors, ExceptionBehaviors) {
EXCEPTION_STATE_IDENTITY}, EXCEPTION_STATE_IDENTITY},
}; };
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto& test_data = kTestData[index]; const auto& test_data = kTestData[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %zu, behavior %d", index, test_data.behavior)); "index %zu, behavior %d", index, test_data.behavior));

View File

@ -20,7 +20,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -71,7 +72,7 @@ TEST(ExceptionTypes, ExcCrashRecoverOriginalException) {
// TODO(macos_arm64): Add arm64 test data. // TODO(macos_arm64): Add arm64 test data.
}; };
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto& test_data = kTestData[index]; const auto& test_data = kTestData[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %zu, code_0 0x%llx", index, test_data.code_0)); "index %zu, code_0 0x%llx", index, test_data.code_0));
@ -88,7 +89,7 @@ TEST(ExceptionTypes, ExcCrashRecoverOriginalException) {
// Now make sure that ExcCrashRecoverOriginalException() properly ignores // Now make sure that ExcCrashRecoverOriginalException() properly ignores
// optional arguments. // optional arguments.
static_assert(base::size(kTestData) >= 1, "must have something to test"); static_assert(std::size(kTestData) >= 1, "must have something to test");
const auto& test_data = kTestData[0]; const auto& test_data = kTestData[0];
EXPECT_EQ( EXPECT_EQ(
ExcCrashRecoverOriginalException(test_data.code_0, nullptr, nullptr), ExcCrashRecoverOriginalException(test_data.code_0, nullptr, nullptr),
@ -248,7 +249,7 @@ TEST(ExceptionTypes, ExceptionCodeForMetrics) {
{0x00010000, 0x00010000, static_cast<int32_t>(0xffffffff)}, {0x00010000, 0x00010000, static_cast<int32_t>(0xffffffff)},
}; };
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto& test_data = kTestData[index]; const auto& test_data = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %zu, exception 0x%x, code_0 0x%llx", SCOPED_TRACE(base::StringPrintf("index %zu, exception 0x%x, code_0 0x%llx",
index, index,

View File

@ -19,9 +19,9 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <iterator>
#include <set> #include <set>
#include "base/cxx17_backports.h"
#include "base/mac/scoped_mach_port.h" #include "base/mac/scoped_mach_port.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "test/mac/mach_errors.h" #include "test/mac/mach_errors.h"
@ -284,7 +284,7 @@ class TestMachMessageServer : public MachMessageServer::Interface,
std::set<mach_msg_id_t> MachMessageServerRequestIDs() override { std::set<mach_msg_id_t> MachMessageServerRequestIDs() override {
static constexpr mach_msg_id_t request_ids[] = {kRequestMessageID}; static constexpr mach_msg_id_t request_ids[] = {kRequestMessageID};
return std::set<mach_msg_id_t>(&request_ids[0], return std::set<mach_msg_id_t>(&request_ids[0],
&request_ids[base::size(request_ids)]); &request_ids[std::size(request_ids)]);
} }
mach_msg_size_t MachMessageServerRequestSize() override { mach_msg_size_t MachMessageServerRequestSize() override {

View File

@ -14,7 +14,8 @@
#include "util/mach/notify_server.h" #include "util/mach/notify_server.h"
#include "base/cxx17_backports.h" #include <iterator>
#include "util/mach/mach_message.h" #include "util/mach/mach_message.h"
#include "util/mach/notifyServer.h" #include "util/mach/notifyServer.h"
@ -227,7 +228,7 @@ std::set<mach_msg_id_t> NotifyServer::MachMessageServerRequestIDs() {
MACH_NOTIFY_DEAD_NAME, MACH_NOTIFY_DEAD_NAME,
}; };
return std::set<mach_msg_id_t>(&request_ids[0], return std::set<mach_msg_id_t>(&request_ids[0],
&request_ids[base::size(request_ids)]); &request_ids[std::size(request_ids)]);
} }
mach_msg_size_t NotifyServer::MachMessageServerRequestSize() { mach_msg_size_t NotifyServer::MachMessageServerRequestSize() {

View File

@ -17,7 +17,8 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "util/mach/exception_behaviors.h" #include "util/mach/exception_behaviors.h"
#include "util/mach/mach_extensions.h" #include "util/mach/mach_extensions.h"
@ -45,7 +46,7 @@ constexpr const char* kExceptionNames[] = {
"GUARD", "GUARD",
"CORPSE_NOTIFY", "CORPSE_NOTIFY",
}; };
static_assert(base::size(kExceptionNames) == EXC_TYPES_COUNT, static_assert(std::size(kExceptionNames) == EXC_TYPES_COUNT,
"kExceptionNames length"); "kExceptionNames length");
constexpr char kExcPrefix[] = "EXC_"; constexpr char kExcPrefix[] = "EXC_";
@ -170,7 +171,7 @@ std::string ThreadStateFlavorFullToShort(const base::StringPiece& flavor) {
{"_STATE32", "32"}, {"_STATE32", "32"},
{"_STATE64", "64"}, {"_STATE64", "64"},
}; };
for (size_t suffix_index = 0; suffix_index < base::size(kStateSuffixes); for (size_t suffix_index = 0; suffix_index < std::size(kStateSuffixes);
++suffix_index) { ++suffix_index) {
const char* suffix = kStateSuffixes[suffix_index].orig; const char* suffix = kStateSuffixes[suffix_index].orig;
size_t suffix_len = strlen(suffix); size_t suffix_len = strlen(suffix);
@ -194,7 +195,7 @@ namespace crashpad {
std::string ExceptionToString(exception_type_t exception, std::string ExceptionToString(exception_type_t exception,
SymbolicConstantToStringOptions options) { SymbolicConstantToStringOptions options) {
const char* exception_name = const char* exception_name =
implicit_cast<size_t>(exception) < base::size(kExceptionNames) implicit_cast<size_t>(exception) < std::size(kExceptionNames)
? kExceptionNames[exception] ? kExceptionNames[exception]
: nullptr; : nullptr;
if (!exception_name) { if (!exception_name) {
@ -220,7 +221,7 @@ bool StringToException(const base::StringPiece& string,
base::StringPiece short_string = base::StringPiece short_string =
can_match_full ? string.substr(strlen(kExcPrefix)) : string; can_match_full ? string.substr(strlen(kExcPrefix)) : string;
for (exception_type_t index = 0; for (exception_type_t index = 0;
index < implicit_cast<exception_type_t>(base::size(kExceptionNames)); index < implicit_cast<exception_type_t>(std::size(kExceptionNames));
++index) { ++index) {
const char* exception_name = kExceptionNames[index]; const char* exception_name = kExceptionNames[index];
if (!exception_name) { if (!exception_name) {
@ -250,7 +251,7 @@ std::string ExceptionMaskToString(exception_mask_t exception_mask,
exception_mask_t local_exception_mask = exception_mask; exception_mask_t local_exception_mask = exception_mask;
std::string mask_string; std::string mask_string;
bool has_forbidden_or = false; bool has_forbidden_or = false;
for (size_t exception = 0; exception < base::size(kExceptionNames); for (size_t exception = 0; exception < std::size(kExceptionNames);
++exception) { ++exception) {
const char* exception_name = kExceptionNames[exception]; const char* exception_name = kExceptionNames[exception];
exception_mask_t exception_mask_value = 1 << exception; exception_mask_t exception_mask_value = 1 << exception;
@ -324,7 +325,7 @@ bool StringToExceptionMask(const base::StringPiece& string,
base::StringPiece short_string = base::StringPiece short_string =
can_match_full ? string.substr(strlen(kExcMaskPrefix)) : string; can_match_full ? string.substr(strlen(kExcMaskPrefix)) : string;
for (exception_type_t index = 0; for (exception_type_t index = 0;
index < implicit_cast<exception_type_t>(base::size(kExceptionNames)); index < implicit_cast<exception_type_t>(std::size(kExceptionNames));
++index) { ++index) {
const char* exception_name = kExceptionNames[index]; const char* exception_name = kExceptionNames[index];
if (!exception_name) { if (!exception_name) {
@ -363,7 +364,7 @@ std::string ExceptionBehaviorToString(exception_behavior_t behavior,
const exception_behavior_t basic_behavior = ExceptionBehaviorBasic(behavior); const exception_behavior_t basic_behavior = ExceptionBehaviorBasic(behavior);
const char* behavior_name = const char* behavior_name =
implicit_cast<size_t>(basic_behavior) < base::size(kBehaviorNames) implicit_cast<size_t>(basic_behavior) < std::size(kBehaviorNames)
? kBehaviorNames[basic_behavior] ? kBehaviorNames[basic_behavior]
: nullptr; : nullptr;
if (!behavior_name) { if (!behavior_name) {
@ -430,8 +431,7 @@ bool StringToExceptionBehavior(const base::StringPiece& string,
base::StringPiece short_string = base::StringPiece short_string =
can_match_full ? sp.substr(strlen(kBehaviorPrefix)) : sp; can_match_full ? sp.substr(strlen(kBehaviorPrefix)) : sp;
for (exception_behavior_t index = 0; for (exception_behavior_t index = 0;
index < index < implicit_cast<exception_behavior_t>(std::size(kBehaviorNames));
implicit_cast<exception_behavior_t>(base::size(kBehaviorNames));
++index) { ++index) {
const char* behavior_name = kBehaviorNames[index]; const char* behavior_name = kBehaviorNames[index];
if (!behavior_name) { if (!behavior_name) {
@ -467,13 +467,13 @@ bool StringToExceptionBehavior(const base::StringPiece& string,
std::string ThreadStateFlavorToString(thread_state_flavor_t flavor, std::string ThreadStateFlavorToString(thread_state_flavor_t flavor,
SymbolicConstantToStringOptions options) { SymbolicConstantToStringOptions options) {
const char* flavor_name = const char* flavor_name =
implicit_cast<size_t>(flavor) < base::size(kFlavorNames) implicit_cast<size_t>(flavor) < std::size(kFlavorNames)
? kFlavorNames[flavor] ? kFlavorNames[flavor]
: nullptr; : nullptr;
if (!flavor_name) { if (!flavor_name) {
for (size_t generic_flavor_index = 0; for (size_t generic_flavor_index = 0;
generic_flavor_index < base::size(kGenericFlavorNames); generic_flavor_index < std::size(kGenericFlavorNames);
++generic_flavor_index) { ++generic_flavor_index) {
if (flavor == kGenericFlavorNames[generic_flavor_index].flavor) { if (flavor == kGenericFlavorNames[generic_flavor_index].flavor) {
flavor_name = kGenericFlavorNames[generic_flavor_index].name; flavor_name = kGenericFlavorNames[generic_flavor_index].name;
@ -500,7 +500,7 @@ bool StringToThreadStateFlavor(const base::StringPiece& string,
thread_state_flavor_t* flavor) { thread_state_flavor_t* flavor) {
if ((options & kAllowFullName) || (options & kAllowShortName)) { if ((options & kAllowFullName) || (options & kAllowShortName)) {
for (thread_state_flavor_t index = 0; for (thread_state_flavor_t index = 0;
index < implicit_cast<thread_state_flavor_t>(base::size(kFlavorNames)); index < implicit_cast<thread_state_flavor_t>(std::size(kFlavorNames));
++index) { ++index) {
const char* flavor_name = kFlavorNames[index]; const char* flavor_name = kFlavorNames[index];
if (!flavor_name) { if (!flavor_name) {
@ -520,7 +520,7 @@ bool StringToThreadStateFlavor(const base::StringPiece& string,
} }
for (size_t generic_flavor_index = 0; for (size_t generic_flavor_index = 0;
generic_flavor_index < base::size(kGenericFlavorNames); generic_flavor_index < std::size(kGenericFlavorNames);
++generic_flavor_index) { ++generic_flavor_index) {
const char* flavor_name = kGenericFlavorNames[generic_flavor_index].name; const char* flavor_name = kGenericFlavorNames[generic_flavor_index].name;
thread_state_flavor_t flavor_number = thread_state_flavor_t flavor_number =

View File

@ -18,7 +18,8 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -26,7 +27,7 @@
#include "util/misc/implicit_cast.h" #include "util/misc/implicit_cast.h"
#define NUL_TEST_DATA(string) \ #define NUL_TEST_DATA(string) \
{ string, base::size(string) - 1 } { string, std::size(string) - 1 }
namespace crashpad { namespace crashpad {
namespace test { namespace test {
@ -160,7 +161,7 @@ void TestExceptionToString(exception_type_t value,
} }
TEST(SymbolicConstantsMach, ExceptionToString) { TEST(SymbolicConstantsMach, ExceptionToString) {
for (size_t index = 0; index < base::size(kExceptionTestData); ++index) { for (size_t index = 0; index < std::size(kExceptionTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
TestExceptionToString(kExceptionTestData[index].exception, TestExceptionToString(kExceptionTestData[index].exception,
kExceptionTestData[index].full_name, kExceptionTestData[index].full_name,
@ -188,11 +189,11 @@ void TestStringToException(const base::StringPiece& string,
} }
TEST(SymbolicConstantsMach, StringToException) { TEST(SymbolicConstantsMach, StringToException) {
for (size_t option_index = 0; option_index < base::size(kNormalOptions); for (size_t option_index = 0; option_index < std::size(kNormalOptions);
++option_index) { ++option_index) {
SCOPED_TRACE(base::StringPrintf("option_index %zu", option_index)); SCOPED_TRACE(base::StringPrintf("option_index %zu", option_index));
StringToSymbolicConstantOptions options = kNormalOptions[option_index]; StringToSymbolicConstantOptions options = kNormalOptions[option_index];
for (size_t index = 0; index < base::size(kExceptionTestData); ++index) { for (size_t index = 0; index < std::size(kExceptionTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
exception_type_t exception = kExceptionTestData[index].exception; exception_type_t exception = kExceptionTestData[index].exception;
{ {
@ -230,7 +231,7 @@ TEST(SymbolicConstantsMach, StringToException) {
"", "",
}; };
for (size_t index = 0; index < base::size(kNegativeTestData); ++index) { for (size_t index = 0; index < std::size(kNegativeTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
TestStringToException(kNegativeTestData[index], options, false, 0); TestStringToException(kNegativeTestData[index], options, false, 0);
} }
@ -251,7 +252,7 @@ TEST(SymbolicConstantsMach, StringToException) {
NUL_TEST_DATA("1\0002"), NUL_TEST_DATA("1\0002"),
}; };
for (size_t index = 0; index < base::size(kNULTestData); ++index) { for (size_t index = 0; index < std::size(kNULTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
base::StringPiece string(kNULTestData[index].string, base::StringPiece string(kNULTestData[index].string,
kNULTestData[index].length); kNULTestData[index].length);
@ -334,7 +335,7 @@ void TestExceptionMaskToString(exception_mask_t value,
} }
TEST(SymbolicConstantsMach, ExceptionMaskToString) { TEST(SymbolicConstantsMach, ExceptionMaskToString) {
for (size_t index = 0; index < base::size(kExceptionMaskTestData); ++index) { for (size_t index = 0; index < std::size(kExceptionMaskTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
TestExceptionMaskToString(kExceptionMaskTestData[index].exception_mask, TestExceptionMaskToString(kExceptionMaskTestData[index].exception_mask,
kExceptionMaskTestData[index].full_name, kExceptionMaskTestData[index].full_name,
@ -389,12 +390,11 @@ TEST(SymbolicConstantsMach, StringToExceptionMask) {
kAllowFullName | kAllowShortName | kAllowNumber | kAllowOr, kAllowFullName | kAllowShortName | kAllowNumber | kAllowOr,
}; };
for (size_t option_index = 0; option_index < base::size(kOptions); for (size_t option_index = 0; option_index < std::size(kOptions);
++option_index) { ++option_index) {
SCOPED_TRACE(base::StringPrintf("option_index %zu", option_index)); SCOPED_TRACE(base::StringPrintf("option_index %zu", option_index));
StringToSymbolicConstantOptions options = kOptions[option_index]; StringToSymbolicConstantOptions options = kOptions[option_index];
for (size_t index = 0; index < base::size(kExceptionMaskTestData); for (size_t index = 0; index < std::size(kExceptionMaskTestData); ++index) {
++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
exception_mask_t exception_mask = exception_mask_t exception_mask =
kExceptionMaskTestData[index].exception_mask; kExceptionMaskTestData[index].exception_mask;
@ -445,7 +445,7 @@ TEST(SymbolicConstantsMach, StringToExceptionMask) {
"", "",
}; };
for (size_t index = 0; index < base::size(kNegativeTestData); ++index) { for (size_t index = 0; index < std::size(kNegativeTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
TestStringToExceptionMask(kNegativeTestData[index], options, false, 0); TestStringToExceptionMask(kNegativeTestData[index], options, false, 0);
} }
@ -471,7 +471,7 @@ TEST(SymbolicConstantsMach, StringToExceptionMask) {
NUL_TEST_DATA("ARITHMETIC|\0EMULATION"), NUL_TEST_DATA("ARITHMETIC|\0EMULATION"),
}; };
for (size_t index = 0; index < base::size(kNULTestData); ++index) { for (size_t index = 0; index < std::size(kNULTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
base::StringPiece string(kNULTestData[index].string, base::StringPiece string(kNULTestData[index].string,
kNULTestData[index].length); kNULTestData[index].length);
@ -506,7 +506,7 @@ TEST(SymbolicConstantsMach, StringToExceptionMask) {
EXC_MASK_SYSCALL | 0x100}, EXC_MASK_SYSCALL | 0x100},
}; };
for (size_t index = 0; index < base::size(kNonCanonicalTestData); ++index) { for (size_t index = 0; index < std::size(kNonCanonicalTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
TestStringToExceptionMask(kNonCanonicalTestData[index].string, TestStringToExceptionMask(kNonCanonicalTestData[index].string,
kNonCanonicalTestData[index].options, kNonCanonicalTestData[index].options,
@ -577,7 +577,7 @@ void TestExceptionBehaviorToString(exception_behavior_t value,
} }
TEST(SymbolicConstantsMach, ExceptionBehaviorToString) { TEST(SymbolicConstantsMach, ExceptionBehaviorToString) {
for (size_t index = 0; index < base::size(kExceptionBehaviorTestData); for (size_t index = 0; index < std::size(kExceptionBehaviorTestData);
++index) { ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
TestExceptionBehaviorToString(kExceptionBehaviorTestData[index].behavior, TestExceptionBehaviorToString(kExceptionBehaviorTestData[index].behavior,
@ -607,11 +607,11 @@ void TestStringToExceptionBehavior(const base::StringPiece& string,
} }
TEST(SymbolicConstantsMach, StringToExceptionBehavior) { TEST(SymbolicConstantsMach, StringToExceptionBehavior) {
for (size_t option_index = 0; option_index < base::size(kNormalOptions); for (size_t option_index = 0; option_index < std::size(kNormalOptions);
++option_index) { ++option_index) {
SCOPED_TRACE(base::StringPrintf("option_index %zu", option_index)); SCOPED_TRACE(base::StringPrintf("option_index %zu", option_index));
StringToSymbolicConstantOptions options = kNormalOptions[option_index]; StringToSymbolicConstantOptions options = kNormalOptions[option_index];
for (size_t index = 0; index < base::size(kExceptionBehaviorTestData); for (size_t index = 0; index < std::size(kExceptionBehaviorTestData);
++index) { ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
exception_behavior_t behavior = exception_behavior_t behavior =
@ -657,7 +657,7 @@ TEST(SymbolicConstantsMach, StringToExceptionBehavior) {
"", "",
}; };
for (size_t index = 0; index < base::size(kNegativeTestData); ++index) { for (size_t index = 0; index < std::size(kNegativeTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
TestStringToExceptionBehavior( TestStringToExceptionBehavior(
kNegativeTestData[index], options, false, 0); kNegativeTestData[index], options, false, 0);
@ -683,7 +683,7 @@ TEST(SymbolicConstantsMach, StringToExceptionBehavior) {
NUL_TEST_DATA("STATE_IDENTITY|\0MACH"), NUL_TEST_DATA("STATE_IDENTITY|\0MACH"),
}; };
for (size_t index = 0; index < base::size(kNULTestData); ++index) { for (size_t index = 0; index < std::size(kNULTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
base::StringPiece string(kNULTestData[index].string, base::StringPiece string(kNULTestData[index].string,
kNULTestData[index].length); kNULTestData[index].length);
@ -720,7 +720,7 @@ TEST(SymbolicConstantsMach, StringToExceptionBehavior) {
implicit_cast<exception_behavior_t>(MACH_EXCEPTION_CODES | 0x2)}, implicit_cast<exception_behavior_t>(MACH_EXCEPTION_CODES | 0x2)},
}; };
for (size_t index = 0; index < base::size(kNonCanonicalTestData); ++index) { for (size_t index = 0; index < std::size(kNonCanonicalTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
TestStringToExceptionBehavior(kNonCanonicalTestData[index].string, TestStringToExceptionBehavior(kNonCanonicalTestData[index].string,
kNonCanonicalTestData[index].options, kNonCanonicalTestData[index].options,
@ -837,7 +837,7 @@ void TestThreadStateFlavorToString(exception_type_t value,
} }
TEST(SymbolicConstantsMach, ThreadStateFlavorToString) { TEST(SymbolicConstantsMach, ThreadStateFlavorToString) {
for (size_t index = 0; index < base::size(kThreadStateFlavorTestData); for (size_t index = 0; index < std::size(kThreadStateFlavorTestData);
++index) { ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
TestThreadStateFlavorToString(kThreadStateFlavorTestData[index].flavor, TestThreadStateFlavorToString(kThreadStateFlavorTestData[index].flavor,
@ -879,11 +879,11 @@ void TestStringToThreadStateFlavor(const base::StringPiece& string,
} }
TEST(SymbolicConstantsMach, StringToThreadStateFlavor) { TEST(SymbolicConstantsMach, StringToThreadStateFlavor) {
for (size_t option_index = 0; option_index < base::size(kNormalOptions); for (size_t option_index = 0; option_index < std::size(kNormalOptions);
++option_index) { ++option_index) {
SCOPED_TRACE(base::StringPrintf("option_index %zu", option_index)); SCOPED_TRACE(base::StringPrintf("option_index %zu", option_index));
StringToSymbolicConstantOptions options = kNormalOptions[option_index]; StringToSymbolicConstantOptions options = kNormalOptions[option_index];
for (size_t index = 0; index < base::size(kThreadStateFlavorTestData); for (size_t index = 0; index < std::size(kThreadStateFlavorTestData);
++index) { ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
thread_state_flavor_t flavor = kThreadStateFlavorTestData[index].flavor; thread_state_flavor_t flavor = kThreadStateFlavorTestData[index].flavor;
@ -953,7 +953,7 @@ TEST(SymbolicConstantsMach, StringToThreadStateFlavor) {
#endif #endif
}; };
for (size_t index = 0; index < base::size(kNegativeTestData); ++index) { for (size_t index = 0; index < std::size(kNegativeTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
TestStringToThreadStateFlavor( TestStringToThreadStateFlavor(
kNegativeTestData[index], options, false, 0); kNegativeTestData[index], options, false, 0);
@ -1019,7 +1019,7 @@ TEST(SymbolicConstantsMach, StringToThreadStateFlavor) {
#endif #endif
}; };
for (size_t index = 0; index < base::size(kNULTestData); ++index) { for (size_t index = 0; index < std::size(kNULTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
base::StringPiece string(kNULTestData[index].string, base::StringPiece string(kNULTestData[index].string,
kNULTestData[index].length); kNULTestData[index].length);

View File

@ -35,9 +35,9 @@ constexpr size_t ArraySizeHelper() noexcept {
//! \brief A way of computing an arrays size. //! \brief A way of computing an arrays size.
//! //!
//! Use this only where `base::size()` or `std::size()` wont work, such as in //! Use this only where `std::size()` wont work, such as in constant
//! constant expressions (including `static_assert` expressions) that consider //! expressions (including `static_assert` expressions) that consider the
//! the sizes of non-static data members. //! sizes of non-static data members.
#define ArraySize(array) crashpad::internal::ArraySizeHelper<decltype(array)>() #define ArraySize(array) crashpad::internal::ArraySizeHelper<decltype(array)>()
#endif // CRASHPAD_UTIL_MISC_ARRAYSIZE_H_ #endif // CRASHPAD_UTIL_MISC_ARRAYSIZE_H_

View File

@ -13,10 +13,11 @@
// limitations under the License. // limitations under the License.
#include "util/misc/capture_context_test_util.h" #include "util/misc/capture_context_test_util.h"
#include "util/win/context_wrappers.h"
#include "base/cxx17_backports.h" #include <iterator>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "util/win/context_wrappers.h"
namespace crashpad { namespace crashpad {
namespace test { namespace test {
@ -59,7 +60,7 @@ void SanityCheckContext(const NativeCPUContext& context) {
#if defined(ARCH_CPU_X86) #if defined(ARCH_CPU_X86)
// fxsave doesnt write these bytes. // fxsave doesnt write these bytes.
for (size_t i = 464; i < base::size(context.ExtendedRegisters); ++i) { for (size_t i = 464; i < std::size(context.ExtendedRegisters); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
EXPECT_EQ(context.ExtendedRegisters[i], 0); EXPECT_EQ(context.ExtendedRegisters[i], 0);
} }
@ -69,7 +70,7 @@ void SanityCheckContext(const NativeCPUContext& context) {
EXPECT_EQ(context.FltSave.MxCsr, context.MxCsr); EXPECT_EQ(context.FltSave.MxCsr, context.MxCsr);
// fxsave doesnt write these bytes. // fxsave doesnt write these bytes.
for (size_t i = 0; i < base::size(context.FltSave.Reserved4); ++i) { for (size_t i = 0; i < std::size(context.FltSave.Reserved4); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
EXPECT_EQ(context.FltSave.Reserved4[i], 0); EXPECT_EQ(context.FltSave.Reserved4[i], 0);
} }
@ -81,7 +82,7 @@ void SanityCheckContext(const NativeCPUContext& context) {
EXPECT_EQ(context.P4Home, 0u); EXPECT_EQ(context.P4Home, 0u);
EXPECT_EQ(context.P5Home, 0u); EXPECT_EQ(context.P5Home, 0u);
EXPECT_EQ(context.P6Home, 0u); EXPECT_EQ(context.P6Home, 0u);
for (size_t i = 0; i < base::size(context.VectorRegister); ++i) { for (size_t i = 0; i < std::size(context.VectorRegister); ++i) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
EXPECT_EQ(context.VectorRegister[i].Low, 0u); EXPECT_EQ(context.VectorRegister[i].Low, 0u);
EXPECT_EQ(context.VectorRegister[i].High, 0u); EXPECT_EQ(context.VectorRegister[i].High, 0u);

View File

@ -17,8 +17,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <algorithm> #include <algorithm>
#include <iterator>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
@ -83,7 +83,7 @@ TEST(Clock, SleepNanoseconds) {
static_cast<uint64_t>(5E7), // 50 milliseconds static_cast<uint64_t>(5E7), // 50 milliseconds
}; };
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const uint64_t nanoseconds = kTestData[index]; const uint64_t nanoseconds = kTestData[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %zu, nanoseconds %" PRIu64, index, nanoseconds)); "index %zu, nanoseconds %" PRIu64, index, nanoseconds));

View File

@ -16,7 +16,8 @@
#include <windows.h> #include <windows.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/logging.h" #include "base/logging.h"
namespace crashpad { namespace crashpad {
@ -24,14 +25,12 @@ namespace crashpad {
// static // static
bool Paths::Executable(base::FilePath* path) { bool Paths::Executable(base::FilePath* path) {
wchar_t executable_path[_MAX_PATH]; wchar_t executable_path[_MAX_PATH];
unsigned int len = unsigned int len = GetModuleFileName(
GetModuleFileName(nullptr, nullptr, executable_path, static_cast<DWORD>(std::size(executable_path)));
executable_path,
static_cast<DWORD>(base::size(executable_path)));
if (len == 0) { if (len == 0) {
PLOG(ERROR) << "GetModuleFileName"; PLOG(ERROR) << "GetModuleFileName";
return false; return false;
} else if (len >= base::size(executable_path)) { } else if (len >= std::size(executable_path)) {
LOG(ERROR) << "GetModuleFileName"; LOG(ERROR) << "GetModuleFileName";
return false; return false;
} }

View File

@ -16,9 +16,9 @@
#include <sys/types.h> #include <sys/types.h>
#include <iterator>
#include <set> #include <set>
#include "base/cxx17_backports.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace crashpad { namespace crashpad {
@ -33,7 +33,7 @@ TEST(RandomString, RandomString) {
const std::string allowed_characters("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); const std::string allowed_characters("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
size_t character_counts[26] = {}; size_t character_counts[26] = {};
ASSERT_EQ(allowed_characters.size(), base::size(character_counts)); ASSERT_EQ(allowed_characters.size(), std::size(character_counts));
std::set<std::string> strings; std::set<std::string> strings;
@ -61,7 +61,7 @@ TEST(RandomString, RandomString) {
// Make sure every character appears at least once. It is possible, but // Make sure every character appears at least once. It is possible, but
// extremely unlikely, for a character to not appear at all. // extremely unlikely, for a character to not appear at all.
for (size_t character_index = 0; for (size_t character_index = 0;
character_index < base::size(character_counts); character_index < std::size(character_counts);
++character_index) { ++character_index) {
EXPECT_GT(character_counts[character_index], 0u) EXPECT_GT(character_counts[character_index], 0u)
<< allowed_characters[character_index]; << allowed_characters[character_index];

View File

@ -17,9 +17,9 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <iterator>
#include <string> #include <string>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/scoped_generic.h" #include "base/scoped_generic.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
@ -110,13 +110,13 @@ TEST(UUID, UUID) {
EXPECT_NE(uuid, uuid_2); EXPECT_NE(uuid, uuid_2);
EXPECT_LT(uuid_2, uuid); EXPECT_LT(uuid_2, uuid);
--uuid.data_3; --uuid.data_3;
for (size_t index = 0; index < base::size(uuid.data_4); ++index) { for (size_t index = 0; index < std::size(uuid.data_4); ++index) {
++uuid.data_4[index]; ++uuid.data_4[index];
EXPECT_NE(uuid, uuid_2); EXPECT_NE(uuid, uuid_2);
EXPECT_LT(uuid_2, uuid); EXPECT_LT(uuid_2, uuid);
--uuid.data_4[index]; --uuid.data_4[index];
} }
for (size_t index = 0; index < base::size(uuid.data_5); ++index) { for (size_t index = 0; index < std::size(uuid.data_5); ++index) {
++uuid.data_5[index]; ++uuid.data_5[index];
EXPECT_NE(uuid, uuid_2); EXPECT_NE(uuid, uuid_2);
EXPECT_LT(uuid_2, uuid); EXPECT_LT(uuid_2, uuid);
@ -207,7 +207,7 @@ TEST(UUID, FromString) {
uuid_zero.InitializeToZero(); uuid_zero.InitializeToZero();
const std::string empty_uuid = uuid_zero.ToString(); const std::string empty_uuid = uuid_zero.ToString();
for (size_t index = 0; index < base::size(kCases); ++index) { for (size_t index = 0; index < std::size(kCases); ++index) {
const TestCase& test_case = kCases[index]; const TestCase& test_case = kCases[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %" PRIuS ": %s", index, test_case.uuid_string)); "index %" PRIuS ": %s", index, test_case.uuid_string));

View File

@ -12,15 +12,14 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "util/net/http_transport.h"
#include <fcntl.h> #include <fcntl.h>
#include <netdb.h> #include <netdb.h>
#include <poll.h> #include <poll.h>
#include <string.h> #include <string.h>
#include <sys/socket.h> #include <sys/socket.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/logging.h" #include "base/logging.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
@ -30,6 +29,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "util/file/file_io.h" #include "util/file/file_io.h"
#include "util/net/http_body.h" #include "util/net/http_body.h"
#include "util/net/http_transport.h"
#include "util/net/url.h" #include "util/net/url.h"
#include "util/stdlib/string_number_conversion.h" #include "util/stdlib/string_number_conversion.h"
#include "util/string/split_string.h" #include "util/string/split_string.h"
@ -371,7 +371,7 @@ bool WriteRequest(Stream* stream,
FileOperationResult data_bytes; FileOperationResult data_bytes;
do { do {
constexpr size_t kCRLFSize = base::size(kCRLFTerminator) - 1; constexpr size_t kCRLFSize = std::size(kCRLFTerminator) - 1;
struct __attribute__((packed)) { struct __attribute__((packed)) {
char size[8]; char size[8];
char crlf[2]; char crlf[2];

View File

@ -22,7 +22,8 @@
#include <wchar.h> #include <wchar.h>
#include <winhttp.h> #include <winhttp.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/logging.h" #include "base/logging.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/scoped_generic.h" #include "base/scoped_generic.h"
@ -96,7 +97,7 @@ std::string WinHttpMessage(const char* extra) {
error_code, error_code,
0, 0,
msgbuf, msgbuf,
static_cast<DWORD>(base::size(msgbuf)), static_cast<DWORD>(std::size(msgbuf)),
nullptr); nullptr);
if (!len) { if (!len) {
return base::StringPrintf("%s: error 0x%lx while retrieving error 0x%lx", return base::StringPrintf("%s: error 0x%lx while retrieving error 0x%lx",

View File

@ -16,9 +16,9 @@
#include <sys/types.h> #include <sys/types.h>
#include <iterator>
#include <limits> #include <limits>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
@ -119,7 +119,7 @@ TEST(CheckedAddressRange, IsValid) {
{0xffffffffffffffff, 1, kInvalid}, {0xffffffffffffffff, 1, kInvalid},
}; };
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %" PRIuS SCOPED_TRACE(base::StringPrintf("index %" PRIuS
", base 0x%" PRIx64 ", size 0x%" PRIx64, ", base 0x%" PRIx64 ", size 0x%" PRIx64,
@ -170,7 +170,7 @@ TEST(CheckedAddressRange, ContainsValue) {
CheckedAddressRange parent_range_32(false, 0x2000, 0x1000); CheckedAddressRange parent_range_32(false, 0x2000, 0x1000);
ASSERT_TRUE(parent_range_32.IsValid()); ASSERT_TRUE(parent_range_32.IsValid());
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %" PRIuS ", value 0x%" PRIx64, index, testcase.value)); "index %" PRIuS ", value 0x%" PRIx64, index, testcase.value));
@ -227,7 +227,7 @@ TEST(CheckedAddressRange, ContainsRange) {
CheckedAddressRange parent_range_32(false, 0x2000, 0x1000); CheckedAddressRange parent_range_32(false, 0x2000, 0x1000);
ASSERT_TRUE(parent_range_32.IsValid()); ASSERT_TRUE(parent_range_32.IsValid());
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %" PRIuS SCOPED_TRACE(base::StringPrintf("index %" PRIuS
", base 0x%" PRIx64 ", size 0x%" PRIx64, ", base 0x%" PRIx64 ", size 0x%" PRIx64,

View File

@ -17,9 +17,9 @@
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#include <iterator>
#include <limits> #include <limits>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -78,7 +78,7 @@ TEST(CheckedRange, IsValid) {
{0xffffffff, 0xffffffff, false}, {0xffffffff, 0xffffffff, false},
}; };
for (size_t index = 0; index < base::size(kUnsignedTestData); ++index) { for (size_t index = 0; index < std::size(kUnsignedTestData); ++index) {
const auto& testcase = kUnsignedTestData[index]; const auto& testcase = kUnsignedTestData[index];
SCOPED_TRACE(base::StringPrintf("unsigned index %" PRIuS SCOPED_TRACE(base::StringPrintf("unsigned index %" PRIuS
", base 0x%x, size 0x%x", ", base 0x%x, size 0x%x",
@ -140,7 +140,7 @@ TEST(CheckedRange, IsValid) {
{-1, 0xffffffff, false}, {-1, 0xffffffff, false},
}; };
for (size_t index = 0; index < base::size(kSignedTestData); ++index) { for (size_t index = 0; index < std::size(kSignedTestData); ++index) {
const auto& testcase = kSignedTestData[index]; const auto& testcase = kSignedTestData[index];
SCOPED_TRACE(base::StringPrintf("signed index %" PRIuS SCOPED_TRACE(base::StringPrintf("signed index %" PRIuS
", base 0x%x, size 0x%x", ", base 0x%x, size 0x%x",
@ -186,7 +186,7 @@ TEST(CheckedRange, ContainsValue) {
CheckedRange<uint32_t> parent_range(0x2000, 0x1000); CheckedRange<uint32_t> parent_range(0x2000, 0x1000);
ASSERT_TRUE(parent_range.IsValid()); ASSERT_TRUE(parent_range.IsValid());
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %" PRIuS ", value 0x%x", index, testcase.value)); "index %" PRIuS ", value 0x%x", index, testcase.value));
@ -234,7 +234,7 @@ TEST(CheckedRange, ContainsRange) {
CheckedRange<uint32_t> parent_range(0x2000, 0x1000); CheckedRange<uint32_t> parent_range(0x2000, 0x1000);
ASSERT_TRUE(parent_range.IsValid()); ASSERT_TRUE(parent_range.IsValid());
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x", SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x",
index, index,
@ -287,7 +287,7 @@ TEST(CheckedRange, OverlapsRange) {
CheckedRange<uint32_t> first_range(0x2000, 0x1000); CheckedRange<uint32_t> first_range(0x2000, 0x1000);
ASSERT_TRUE(first_range.IsValid()); ASSERT_TRUE(first_range.IsValid());
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x", SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x",
index, index,

View File

@ -21,8 +21,8 @@
#include <unistd.h> #include <unistd.h>
#include <algorithm> #include <algorithm>
#include <iterator>
#include "base/cxx17_backports.h"
#include "base/files/scoped_file.h" #include "base/files/scoped_file.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
@ -155,7 +155,7 @@ void CloseMultipleNowOrOnExec(int fd, int preserve_fd) {
int maxfilesperproc; int maxfilesperproc;
size_t maxfilesperproc_size = sizeof(maxfilesperproc); size_t maxfilesperproc_size = sizeof(maxfilesperproc);
if (sysctl(oid, if (sysctl(oid,
base::size(oid), std::size(oid),
&maxfilesperproc, &maxfilesperproc,
&maxfilesperproc_size, &maxfilesperproc_size,
nullptr, nullptr,

View File

@ -16,7 +16,8 @@
#include <string.h> #include <string.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/mach_logging.h" #include "base/mac/mach_logging.h"
@ -33,7 +34,7 @@ bool ProcessInfo::InitializeWithPid(pid_t pid) {
int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid}; int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
size_t len = sizeof(kern_proc_info_); size_t len = sizeof(kern_proc_info_);
if (sysctl(mib, base::size(mib), &kern_proc_info_, &len, nullptr, 0) != 0) { if (sysctl(mib, std::size(mib), &kern_proc_info_, &len, nullptr, 0) != 0) {
PLOG(ERROR) << "sysctl for pid " << pid; PLOG(ERROR) << "sysctl for pid " << pid;
return false; return false;
} }
@ -112,7 +113,7 @@ std::set<gid_t> ProcessInfo::SupplementaryGroups() const {
const short ngroups = kern_proc_info_.kp_eproc.e_ucred.cr_ngroups; const short ngroups = kern_proc_info_.kp_eproc.e_ucred.cr_ngroups;
DCHECK_GE(ngroups, 0); DCHECK_GE(ngroups, 0);
DCHECK_LE(static_cast<size_t>(ngroups), DCHECK_LE(static_cast<size_t>(ngroups),
base::size(kern_proc_info_.kp_eproc.e_ucred.cr_groups)); std::size(kern_proc_info_.kp_eproc.e_ucred.cr_groups));
const gid_t* groups = kern_proc_info_.kp_eproc.e_ucred.cr_groups; const gid_t* groups = kern_proc_info_.kp_eproc.e_ucred.cr_groups;
return std::set<gid_t>(&groups[0], &groups[ngroups]); return std::set<gid_t>(&groups[0], &groups[ngroups]);
@ -169,7 +170,7 @@ bool ProcessInfo::Arguments(std::vector<std::string>* argv) const {
do { do {
int mib[] = {CTL_KERN, KERN_PROCARGS2, pid}; int mib[] = {CTL_KERN, KERN_PROCARGS2, pid};
int rv = int rv =
sysctl(mib, base::size(mib), nullptr, &args_size_estimate, nullptr, 0); sysctl(mib, std::size(mib), nullptr, &args_size_estimate, nullptr, 0);
if (rv != 0) { if (rv != 0) {
PLOG(ERROR) << "sysctl (size) for pid " << pid; PLOG(ERROR) << "sysctl (size) for pid " << pid;
return false; return false;
@ -184,7 +185,7 @@ bool ProcessInfo::Arguments(std::vector<std::string>* argv) const {
// for the reasons described above.) // for the reasons described above.)
args_size = args_size_estimate + 32; args_size = args_size_estimate + 32;
args.resize(args_size); args.resize(args_size);
rv = sysctl(mib, base::size(mib), &args[0], &args_size, nullptr, 0); rv = sysctl(mib, std::size(mib), &args[0], &args_size, nullptr, 0);
if (rv != 0) { if (rv != 0) {
PLOG(ERROR) << "sysctl (data) for pid " << pid; PLOG(ERROR) << "sysctl (data) for pid " << pid;
return false; return false;

View File

@ -18,7 +18,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
@ -152,7 +153,7 @@ TEST(ScopedMmapDeathTest, ResetAddrLen_Shrink) {
EXPECT_EQ(mapping.len(), 3 * kPageSize); EXPECT_EQ(mapping.len(), 3 * kPageSize);
TestCookie cookies[3]; TestCookie cookies[3];
for (size_t index = 0; index < base::size(cookies); ++index) { for (size_t index = 0; index < std::size(cookies); ++index) {
cookies[index].SetUp(reinterpret_cast<uint64_t*>( cookies[index].SetUp(reinterpret_cast<uint64_t*>(
mapping.addr_as<uintptr_t>() + index * kPageSize)); mapping.addr_as<uintptr_t>() + index * kPageSize));
} }
@ -187,7 +188,7 @@ TEST(ScopedMmap, ResetAddrLen_Grow) {
EXPECT_EQ(mapping.len(), kPageSize); EXPECT_EQ(mapping.len(), kPageSize);
TestCookie cookies[3]; TestCookie cookies[3];
for (size_t index = 0; index < base::size(cookies); ++index) { for (size_t index = 0; index < std::size(cookies); ++index) {
cookies[index].SetUp(reinterpret_cast<uint64_t*>( cookies[index].SetUp(reinterpret_cast<uint64_t*>(
reinterpret_cast<uintptr_t>(pages) + index * kPageSize)); reinterpret_cast<uintptr_t>(pages) + index * kPageSize));
} }
@ -198,7 +199,7 @@ TEST(ScopedMmap, ResetAddrLen_Grow) {
EXPECT_EQ(mapping.addr(), pages); EXPECT_EQ(mapping.addr(), pages);
EXPECT_EQ(mapping.len(), 3 * kPageSize); EXPECT_EQ(mapping.len(), 3 * kPageSize);
for (size_t index = 0; index < base::size(cookies); ++index) { for (size_t index = 0; index < std::size(cookies); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
EXPECT_EQ(cookies[index].Observed(), cookies[index].Expected()); EXPECT_EQ(cookies[index].Observed(), cookies[index].Expected());
} }
@ -219,7 +220,7 @@ TEST(ScopedMmapDeathTest, ResetAddrLen_MoveDownAndGrow) {
EXPECT_EQ(mapping.len(), kPageSize); EXPECT_EQ(mapping.len(), kPageSize);
TestCookie cookies[3]; TestCookie cookies[3];
for (size_t index = 0; index < base::size(cookies); ++index) { for (size_t index = 0; index < std::size(cookies); ++index) {
cookies[index].SetUp(reinterpret_cast<uint64_t*>( cookies[index].SetUp(reinterpret_cast<uint64_t*>(
reinterpret_cast<uintptr_t>(pages) + index * kPageSize)); reinterpret_cast<uintptr_t>(pages) + index * kPageSize));
} }
@ -250,7 +251,7 @@ TEST(ScopedMmapDeathTest, ResetAddrLen_MoveUpAndShrink) {
EXPECT_EQ(mapping.len(), 2 * kPageSize); EXPECT_EQ(mapping.len(), 2 * kPageSize);
TestCookie cookies[3]; TestCookie cookies[3];
for (size_t index = 0; index < base::size(cookies); ++index) { for (size_t index = 0; index < std::size(cookies); ++index) {
cookies[index].SetUp(reinterpret_cast<uint64_t*>( cookies[index].SetUp(reinterpret_cast<uint64_t*>(
reinterpret_cast<uintptr_t>(pages) + index * kPageSize)); reinterpret_cast<uintptr_t>(pages) + index * kPageSize));
} }
@ -348,7 +349,7 @@ TEST(ScopedMmapDeathTest, NotIntegralNumberOfPages) {
EXPECT_EQ(mapping.len(), 2 * kPageSize); EXPECT_EQ(mapping.len(), 2 * kPageSize);
TestCookie two_cookies[2]; TestCookie two_cookies[2];
for (size_t index = 0; index < base::size(two_cookies); ++index) { for (size_t index = 0; index < std::size(two_cookies); ++index) {
two_cookies[index].SetUp(reinterpret_cast<uint64_t*>( two_cookies[index].SetUp(reinterpret_cast<uint64_t*>(
mapping.addr_as<uintptr_t>() + index * kPageSize)); mapping.addr_as<uintptr_t>() + index * kPageSize));
} }
@ -368,7 +369,7 @@ TEST(ScopedMmapDeathTest, NotIntegralNumberOfPages) {
EXPECT_NE(mapping.addr(), MAP_FAILED); EXPECT_NE(mapping.addr(), MAP_FAILED);
EXPECT_EQ(mapping.len(), 2 * kPageSize); EXPECT_EQ(mapping.len(), 2 * kPageSize);
for (size_t index = 0; index < base::size(two_cookies); ++index) { for (size_t index = 0; index < std::size(two_cookies); ++index) {
two_cookies[index].SetUp(reinterpret_cast<uint64_t*>( two_cookies[index].SetUp(reinterpret_cast<uint64_t*>(
mapping.addr_as<uintptr_t>() + index * kPageSize)); mapping.addr_as<uintptr_t>() + index * kPageSize));
} }

View File

@ -16,10 +16,10 @@
#include <unistd.h> #include <unistd.h>
#include <iterator>
#include <vector> #include <vector>
#include "base/check_op.h" #include "base/check_op.h"
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "build/build_config.h" #include "build/build_config.h"
@ -130,7 +130,7 @@ bool IsSignalInSet(int sig, const int* set, size_t set_size) {
struct sigaction* Signals::OldActions::ActionForSignal(int sig) { struct sigaction* Signals::OldActions::ActionForSignal(int sig) {
DCHECK_GT(sig, 0); DCHECK_GT(sig, 0);
const size_t slot = sig - 1; const size_t slot = sig - 1;
DCHECK_LT(slot, base::size(actions_)); DCHECK_LT(slot, std::size(actions_));
return &actions_[slot]; return &actions_[slot];
} }
@ -165,8 +165,7 @@ bool Signals::InstallCrashHandlers(Handler handler,
OldActions* old_actions, OldActions* old_actions,
const std::set<int>* unhandled_signals) { const std::set<int>* unhandled_signals) {
return InstallHandlers( return InstallHandlers(
std::vector<int>(kCrashSignals, std::vector<int>(kCrashSignals, kCrashSignals + std::size(kCrashSignals)),
kCrashSignals + base::size(kCrashSignals)),
handler, handler,
flags, flags,
old_actions, old_actions,
@ -179,7 +178,7 @@ bool Signals::InstallTerminateHandlers(Handler handler,
OldActions* old_actions) { OldActions* old_actions) {
return InstallHandlers( return InstallHandlers(
std::vector<int>(kTerminateSignals, std::vector<int>(kTerminateSignals,
kTerminateSignals + base::size(kTerminateSignals)), kTerminateSignals + std::size(kTerminateSignals)),
handler, handler,
flags, flags,
old_actions, old_actions,
@ -324,12 +323,12 @@ void Signals::RestoreHandlerAndReraiseSignalOnReturn(
// static // static
bool Signals::IsCrashSignal(int sig) { bool Signals::IsCrashSignal(int sig) {
return IsSignalInSet(sig, kCrashSignals, base::size(kCrashSignals)); return IsSignalInSet(sig, kCrashSignals, std::size(kCrashSignals));
} }
// static // static
bool Signals::IsTerminateSignal(int sig) { bool Signals::IsTerminateSignal(int sig) {
return IsSignalInSet(sig, kTerminateSignals, base::size(kTerminateSignals)); return IsSignalInSet(sig, kTerminateSignals, std::size(kTerminateSignals));
} }
} // namespace crashpad } // namespace crashpad

View File

@ -20,9 +20,9 @@
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include <iterator>
#include <limits> #include <limits>
#include "base/cxx17_backports.h"
#include "base/files/scoped_file.h" #include "base/files/scoped_file.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
@ -410,7 +410,7 @@ TEST(Signals, WillSignalReraiseAutonomously) {
{SIGHUP, SEGV_MAPERR, false}, {SIGHUP, SEGV_MAPERR, false},
{SIGINT, SI_USER, false}, {SIGINT, SI_USER, false},
}; };
for (size_t index = 0; index < base::size(kTestData); ++index) { for (size_t index = 0; index < std::size(kTestData); ++index) {
const auto test_data = kTestData[index]; const auto test_data = kTestData[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %zu, sig %d, code %d", index, test_data.sig, test_data.code)); "index %zu, sig %d, code %d", index, test_data.sig, test_data.code));

View File

@ -18,7 +18,8 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "util/misc/implicit_cast.h" #include "util/misc/implicit_cast.h"
@ -139,9 +140,9 @@ constexpr const char* kSignalNames[] = {
}; };
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
// NSIG is 64 to account for real-time signals. // NSIG is 64 to account for real-time signals.
static_assert(base::size(kSignalNames) == 32, "kSignalNames length"); static_assert(std::size(kSignalNames) == 32, "kSignalNames length");
#else #else
static_assert(base::size(kSignalNames) == NSIG, "kSignalNames length"); static_assert(std::size(kSignalNames) == NSIG, "kSignalNames length");
#endif #endif
constexpr char kSigPrefix[] = "SIG"; constexpr char kSigPrefix[] = "SIG";
@ -153,7 +154,7 @@ namespace crashpad {
std::string SignalToString(int signal, std::string SignalToString(int signal,
SymbolicConstantToStringOptions options) { SymbolicConstantToStringOptions options) {
const char* signal_name = const char* signal_name =
implicit_cast<size_t>(signal) < base::size(kSignalNames) implicit_cast<size_t>(signal) < std::size(kSignalNames)
? kSignalNames[signal] ? kSignalNames[signal]
: nullptr; : nullptr;
if (!signal_name) { if (!signal_name) {
@ -178,7 +179,7 @@ bool StringToSignal(const base::StringPiece& string,
string.substr(0, strlen(kSigPrefix)).compare(kSigPrefix) == 0; string.substr(0, strlen(kSigPrefix)).compare(kSigPrefix) == 0;
base::StringPiece short_string = base::StringPiece short_string =
can_match_full ? string.substr(strlen(kSigPrefix)) : string; can_match_full ? string.substr(strlen(kSigPrefix)) : string;
for (int index = 0; index < implicit_cast<int>(base::size(kSignalNames)); for (int index = 0; index < implicit_cast<int>(std::size(kSignalNames));
++index) { ++index) {
const char* signal_name = kSignalNames[index]; const char* signal_name = kSignalNames[index];
if (!signal_name) { if (!signal_name) {

View File

@ -17,14 +17,15 @@
#include <signal.h> #include <signal.h>
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#define NUL_TEST_DATA(string) \ #define NUL_TEST_DATA(string) \
{ string, base::size(string) - 1 } { string, std::size(string) - 1 }
namespace crashpad { namespace crashpad {
namespace test { namespace test {
@ -101,7 +102,7 @@ void TestSignalToString(int value,
} }
TEST(SymbolicConstantsPOSIX, SignalToString) { TEST(SymbolicConstantsPOSIX, SignalToString) {
for (size_t index = 0; index < base::size(kSignalTestData); ++index) { for (size_t index = 0; index < std::size(kSignalTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
TestSignalToString(kSignalTestData[index].signal, TestSignalToString(kSignalTestData[index].signal,
kSignalTestData[index].full_name, kSignalTestData[index].full_name,
@ -156,11 +157,11 @@ TEST(SymbolicConstantsPOSIX, StringToSignal) {
kAllowFullName | kAllowShortName | kAllowNumber, kAllowFullName | kAllowShortName | kAllowNumber,
}; };
for (size_t option_index = 0; option_index < base::size(kOptions); for (size_t option_index = 0; option_index < std::size(kOptions);
++option_index) { ++option_index) {
SCOPED_TRACE(base::StringPrintf("option_index %zu", option_index)); SCOPED_TRACE(base::StringPrintf("option_index %zu", option_index));
StringToSymbolicConstantOptions options = kOptions[option_index]; StringToSymbolicConstantOptions options = kOptions[option_index];
for (size_t index = 0; index < base::size(kSignalTestData); ++index) { for (size_t index = 0; index < std::size(kSignalTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
int signal = kSignalTestData[index].signal; int signal = kSignalTestData[index].signal;
{ {
@ -198,7 +199,7 @@ TEST(SymbolicConstantsPOSIX, StringToSignal) {
"", "",
}; };
for (size_t index = 0; index < base::size(kNegativeTestData); ++index) { for (size_t index = 0; index < std::size(kNegativeTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
TestStringToSignal(kNegativeTestData[index], options, false, 0); TestStringToSignal(kNegativeTestData[index], options, false, 0);
} }
@ -219,7 +220,7 @@ TEST(SymbolicConstantsPOSIX, StringToSignal) {
NUL_TEST_DATA("1\0002"), NUL_TEST_DATA("1\0002"),
}; };
for (size_t index = 0; index < base::size(kNULTestData); ++index) { for (size_t index = 0; index < std::size(kNULTestData); ++index) {
SCOPED_TRACE(base::StringPrintf("index %zu", index)); SCOPED_TRACE(base::StringPrintf("index %zu", index));
base::StringPiece string(kNULTestData[index].string, base::StringPiece string(kNULTestData[index].string,
kNULTestData[index].length); kNULTestData[index].length);

View File

@ -14,9 +14,9 @@
#include "util/process/process_memory_range.h" #include "util/process/process_memory_range.h"
#include <iterator>
#include <limits> #include <limits>
#include "base/cxx17_backports.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "test/process_type.h" #include "test/process_type.h"
@ -69,28 +69,28 @@ TEST(ProcessMemoryRange, Basic) {
auto string1_addr = FromPointerCast<VMAddress>(kTestObject.string1); auto string1_addr = FromPointerCast<VMAddress>(kTestObject.string1);
auto string2_addr = FromPointerCast<VMAddress>(kTestObject.string2); auto string2_addr = FromPointerCast<VMAddress>(kTestObject.string2);
ASSERT_TRUE(range.ReadCStringSizeLimited( ASSERT_TRUE(range.ReadCStringSizeLimited(
string1_addr, base::size(kTestObject.string1), &string)); string1_addr, std::size(kTestObject.string1), &string));
EXPECT_STREQ(string.c_str(), kTestObject.string1); EXPECT_STREQ(string.c_str(), kTestObject.string1);
ASSERT_TRUE(range.ReadCStringSizeLimited( ASSERT_TRUE(range.ReadCStringSizeLimited(
string2_addr, base::size(kTestObject.string2), &string)); string2_addr, std::size(kTestObject.string2), &string));
EXPECT_STREQ(string.c_str(), kTestObject.string2); EXPECT_STREQ(string.c_str(), kTestObject.string2);
// Limit the range to remove access to string2. // Limit the range to remove access to string2.
ProcessMemoryRange range2; ProcessMemoryRange range2;
ASSERT_TRUE(range2.Initialize(range)); ASSERT_TRUE(range2.Initialize(range));
ASSERT_TRUE( ASSERT_TRUE(
range2.RestrictRange(string1_addr, base::size(kTestObject.string1))); range2.RestrictRange(string1_addr, std::size(kTestObject.string1)));
EXPECT_TRUE(range2.ReadCStringSizeLimited( EXPECT_TRUE(range2.ReadCStringSizeLimited(
string1_addr, base::size(kTestObject.string1), &string)); string1_addr, std::size(kTestObject.string1), &string));
EXPECT_FALSE(range2.ReadCStringSizeLimited( EXPECT_FALSE(range2.ReadCStringSizeLimited(
string2_addr, base::size(kTestObject.string2), &string)); string2_addr, std::size(kTestObject.string2), &string));
EXPECT_FALSE(range2.Read(object_addr, sizeof(object), &object)); EXPECT_FALSE(range2.Read(object_addr, sizeof(object), &object));
// String reads fail if the NUL terminator is outside the range. // String reads fail if the NUL terminator is outside the range.
ASSERT_TRUE(range2.RestrictRange(string1_addr, strlen(kTestObject.string1))); ASSERT_TRUE(range2.RestrictRange(string1_addr, strlen(kTestObject.string1)));
EXPECT_FALSE(range2.ReadCStringSizeLimited( EXPECT_FALSE(range2.ReadCStringSizeLimited(
string1_addr, base::size(kTestObject.string1), &string)); string1_addr, std::size(kTestObject.string1), &string));
// New range outside the old range. // New range outside the old range.
EXPECT_FALSE(range2.RestrictRange(string1_addr - 1, 1)); EXPECT_FALSE(range2.RestrictRange(string1_addr - 1, 1));

View File

@ -17,10 +17,10 @@
#include <sys/types.h> #include <sys/types.h>
#include <array> #include <array>
#include <iterator>
#include <limits> #include <limits>
#include <type_traits> #include <type_traits>
#include "base/cxx17_backports.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#define STRINGIFY(a) STR(a) #define STRINGIFY(a) STR(a)
@ -277,7 +277,7 @@ TEST(StringNumberConversion, StringToInt) {
// "decimal digit terminates octal escape sequence". // "decimal digit terminates octal escape sequence".
int output; int output;
std::string kEmbeddedNullInput(kEmbeddedNullInputRaw, std::string kEmbeddedNullInput(kEmbeddedNullInputRaw,
base::size(kEmbeddedNullInputRaw) - 1); std::size(kEmbeddedNullInputRaw) - 1);
EXPECT_FALSE(StringToNumber(kEmbeddedNullInput, &output)); EXPECT_FALSE(StringToNumber(kEmbeddedNullInput, &output));
} }
@ -307,7 +307,7 @@ TEST(StringNumberConversion, StringToUnsignedInt) {
// "decimal digit terminates octal escape sequence". // "decimal digit terminates octal escape sequence".
unsigned int output; unsigned int output;
std::string kEmbeddedNullInput(kEmbeddedNullInputRaw, std::string kEmbeddedNullInput(kEmbeddedNullInputRaw,
base::size(kEmbeddedNullInputRaw) - 1); std::size(kEmbeddedNullInputRaw) - 1);
EXPECT_FALSE(StringToNumber(kEmbeddedNullInput, &output)); EXPECT_FALSE(StringToNumber(kEmbeddedNullInput, &output));
} }

View File

@ -18,9 +18,9 @@
#include <wchar.h> #include <wchar.h>
#include <algorithm> #include <algorithm>
#include <iterator>
#include <string> #include <string>
#include "base/cxx17_backports.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -53,7 +53,7 @@ TEST(strlcpy, c16lcpy) {
static constexpr char16_t test_characters[] = { static constexpr char16_t test_characters[] = {
0x4d, 0xe9, 0x100, 0x151, 0x1e18}; 0x4d, 0xe9, 0x100, 0x151, 0x1e18};
for (size_t index = 0; index < base::size(test_characters); ++index) { for (size_t index = 0; index < std::size(test_characters); ++index) {
char16_t test_character = test_characters[index]; char16_t test_character = test_characters[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"character index %" PRIuS ", character 0x%x", index, test_character)); "character index %" PRIuS ", character 0x%x", index, test_character));
@ -67,13 +67,13 @@ TEST(strlcpy, c16lcpy) {
EXPECT_EQ(c16lcpy(destination.data, EXPECT_EQ(c16lcpy(destination.data,
test_string.c_str(), test_string.c_str(),
base::size(destination.data)), std::size(destination.data)),
length); length);
// Make sure that the destination buffer is NUL-terminated, and that as // Make sure that the destination buffer is NUL-terminated, and that as
// much of the test string was copied as could fit. // much of the test string was copied as could fit.
size_t expected_destination_length = size_t expected_destination_length =
std::min(length, base::size(destination.data) - 1); std::min(length, std::size(destination.data) - 1);
EXPECT_EQ(destination.data[expected_destination_length], '\0'); EXPECT_EQ(destination.data[expected_destination_length], '\0');
EXPECT_EQ(C16Len(destination.data), expected_destination_length); EXPECT_EQ(C16Len(destination.data), expected_destination_length);
@ -86,15 +86,15 @@ TEST(strlcpy, c16lcpy) {
// of the buffer passed to c16lcpy. // of the buffer passed to c16lcpy.
EXPECT_TRUE(C16Memcmp(expected_untouched.lead_guard, EXPECT_TRUE(C16Memcmp(expected_untouched.lead_guard,
destination.lead_guard, destination.lead_guard,
base::size(destination.lead_guard)) == 0); std::size(destination.lead_guard)) == 0);
size_t expected_untouched_length = size_t expected_untouched_length =
base::size(destination.data) - expected_destination_length - 1; std::size(destination.data) - expected_destination_length - 1;
EXPECT_TRUE(C16Memcmp(expected_untouched.data, EXPECT_TRUE(C16Memcmp(expected_untouched.data,
&destination.data[expected_destination_length + 1], &destination.data[expected_destination_length + 1],
expected_untouched_length) == 0); expected_untouched_length) == 0);
EXPECT_TRUE(C16Memcmp(expected_untouched.trail_guard, EXPECT_TRUE(C16Memcmp(expected_untouched.trail_guard,
destination.trail_guard, destination.trail_guard,
base::size(destination.trail_guard)) == 0); std::size(destination.trail_guard)) == 0);
} }
} }
} }

View File

@ -14,7 +14,8 @@
#include "util/stdlib/thread_safe_vector.h" #include "util/stdlib/thread_safe_vector.h"
#include "base/cxx17_backports.h" #include <iterator>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "util/thread/thread.h" #include "util/thread/thread.h"
@ -57,12 +58,12 @@ TEST(ThreadSafeVector, ThreadSafeVector) {
EXPECT_TRUE(vector.empty()); EXPECT_TRUE(vector.empty());
ThreadSafeVectorTestThread threads[100]; ThreadSafeVectorTestThread threads[100];
for (size_t index = 0; index < base::size(threads); ++index) { for (size_t index = 0; index < std::size(threads); ++index) {
threads[index].SetTestParameters( threads[index].SetTestParameters(
&thread_safe_vector, static_cast<int>(index * kElementsPerThread)); &thread_safe_vector, static_cast<int>(index * kElementsPerThread));
} }
for (size_t index = 0; index < base::size(threads); ++index) { for (size_t index = 0; index < std::size(threads); ++index) {
threads[index].Start(); threads[index].Start();
if (index % 10 == 0) { if (index % 10 == 0) {
@ -79,8 +80,8 @@ TEST(ThreadSafeVector, ThreadSafeVector) {
std::vector<int> drained = thread_safe_vector.Drain(); std::vector<int> drained = thread_safe_vector.Drain();
vector.insert(vector.end(), drained.begin(), drained.end()); vector.insert(vector.end(), drained.begin(), drained.end());
bool found[base::size(threads) * kElementsPerThread] = {}; bool found[std::size(threads) * kElementsPerThread] = {};
EXPECT_EQ(vector.size(), base::size(found)); EXPECT_EQ(vector.size(), std::size(found));
for (int element : vector) { for (int element : vector) {
EXPECT_FALSE(found[element]) << element; EXPECT_FALSE(found[element]) << element;
found[element] = true; found[element] = true;

View File

@ -17,9 +17,9 @@
#include <string.h> #include <string.h>
#include <algorithm> #include <algorithm>
#include <iterator>
#include <sstream> #include <sstream>
#include "base/cxx17_backports.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -237,7 +237,7 @@ TEST_F(Base94OutputStreamTest, WriteDeterministicLongDataMultipleTimes) {
4, 96, 40, kLongDataLength - 4 - 96 - 40}; 4, 96, 40, kLongDataLength - 4 - 96 - 40};
size_t offset = 0; size_t offset = 0;
for (size_t index = 0; index < base::size(kWriteLengths); ++index) { for (size_t index = 0; index < std::size(kWriteLengths); ++index) {
const size_t write_length = kWriteLengths[index]; const size_t write_length = kWriteLengths[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"offset %zu, write_length %zu", offset, write_length)); "offset %zu, write_length %zu", offset, write_length));

View File

@ -14,8 +14,9 @@
#include "util/stream/zlib_output_stream.h" #include "util/stream/zlib_output_stream.h"
#include <iterator>
#include "base/check.h" #include "base/check.h"
#include "base/cxx17_backports.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "util/misc/zlib.h" #include "util/misc/zlib.h"
@ -65,7 +66,7 @@ bool ZlibOutputStream::Write(const uint8_t* data, size_t size) {
} }
} }
zlib_stream_.next_out = buffer_; zlib_stream_.next_out = buffer_;
zlib_stream_.avail_out = base::saturated_cast<uInt>(base::size(buffer_)); zlib_stream_.avail_out = base::saturated_cast<uInt>(std::size(buffer_));
initialized_.set_valid(); initialized_.set_valid();
} }
@ -127,12 +128,12 @@ bool ZlibOutputStream::Flush() {
} }
bool ZlibOutputStream::WriteOutputStream() { bool ZlibOutputStream::WriteOutputStream() {
auto valid_size = base::size(buffer_) - zlib_stream_.avail_out; auto valid_size = std::size(buffer_) - zlib_stream_.avail_out;
if (valid_size > 0 && !output_stream_->Write(buffer_, valid_size)) if (valid_size > 0 && !output_stream_->Write(buffer_, valid_size))
return false; return false;
zlib_stream_.next_out = buffer_; zlib_stream_.next_out = buffer_;
zlib_stream_.avail_out = base::saturated_cast<uInt>(base::size(buffer_)); zlib_stream_.avail_out = base::saturated_cast<uInt>(std::size(buffer_));
return true; return true;
} }

View File

@ -17,8 +17,8 @@
#include <string.h> #include <string.h>
#include <algorithm> #include <algorithm>
#include <iterator>
#include "base/cxx17_backports.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -102,7 +102,7 @@ TEST_F(ZlibOutputStreamTest, WriteDeterministicLongDataMultipleTimes) {
4, 96, 40, kLongDataLength - 4 - 96 - 40}; 4, 96, 40, kLongDataLength - 4 - 96 - 40};
size_t offset = 0; size_t offset = 0;
for (size_t index = 0; index < base::size(kWriteLengths); ++index) { for (size_t index = 0; index < std::size(kWriteLengths); ++index) {
const size_t write_length = kWriteLengths[index]; const size_t write_length = kWriteLengths[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"offset %zu, write_length %zu", offset, write_length)); "offset %zu, write_length %zu", offset, write_length));

View File

@ -16,7 +16,8 @@
#include <sys/types.h> #include <sys/types.h>
#include "base/cxx17_backports.h" #include <iterator>
#include "build/build_config.h" #include "build/build_config.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -127,7 +128,7 @@ TEST(Semaphore, TenThreaded) {
Semaphore semaphore(5); Semaphore semaphore(5);
ThreadMainInfo info[10]; ThreadMainInfo info[10];
size_t iterations = 0; size_t iterations = 0;
for (size_t index = 0; index < base::size(info); ++index) { for (size_t index = 0; index < std::size(info); ++index) {
info[index].semaphore = &semaphore; info[index].semaphore = &semaphore;
info[index].iterations = index; info[index].iterations = index;
iterations += info[index].iterations; iterations += info[index].iterations;
@ -139,7 +140,7 @@ TEST(Semaphore, TenThreaded) {
semaphore.Signal(); semaphore.Signal();
} }
for (size_t index = 0; index < base::size(info); ++index) { for (size_t index = 0; index < std::size(info); ++index) {
JoinThread(&info[index]); JoinThread(&info[index]);
} }
} }

Some files were not shown because too many files have changed in this diff Show More