mirror of
https://github.com/chromium/crashpad.git
synced 2025-01-14 01:08:01 +08:00
Use implicit_cast<> instead of static_cast<> whenever possible.
implicit_cast<> only performs a cast in cases where an implicit conversion would be possible. It’s even safer than static_cast<> It’s an “explicit implicit” cast, which is not normally necsesary, but is frequently required when working with the ?: operator, functions like std::min() and std::max(), and logging and testing macros. The public style guide does not mention implicit_cast<> only because it is not part of the standard library, but would otherwise require it in these situations. Since base does provide implicit_cast<>, it should be used whenever possible. The only uses of static_cast<> not converted to implicit_cast<> are those that require static_cast<>, such as those that assign an integer constant to a variable of an enum type. R=rsesek@chromium.org Review URL: https://codereview.chromium.org/700383007
This commit is contained in:
parent
bdfd147a47
commit
48b1964d1b
@ -19,6 +19,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "build/build_config.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -34,10 +35,10 @@ namespace {
|
||||
void SanityCheckContext(NativeCPUContext* context) {
|
||||
#if defined(ARCH_CPU_X86)
|
||||
ASSERT_EQ(x86_THREAD_STATE32, context->tsh.flavor);
|
||||
ASSERT_EQ(static_cast<int>(x86_THREAD_STATE32_COUNT), context->tsh.count);
|
||||
ASSERT_EQ(implicit_cast<int>(x86_THREAD_STATE32_COUNT), context->tsh.count);
|
||||
#elif defined(ARCH_CPU_X86_64)
|
||||
ASSERT_EQ(x86_THREAD_STATE64, context->tsh.flavor);
|
||||
ASSERT_EQ(static_cast<int>(x86_THREAD_STATE64_COUNT), context->tsh.count);
|
||||
ASSERT_EQ(implicit_cast<int>(x86_THREAD_STATE64_COUNT), context->tsh.count);
|
||||
#endif
|
||||
|
||||
#if defined(ARCH_CPU_X86_FAMILY)
|
||||
|
@ -231,7 +231,7 @@ class TSimpleStringDictionary {
|
||||
entry->value[0] = '\0';
|
||||
}
|
||||
|
||||
DCHECK_EQ(GetEntryForKey(key), static_cast<Entry*>(nullptr));
|
||||
DCHECK_EQ(GetEntryForKey(key), implicit_cast<Entry*>(nullptr));
|
||||
}
|
||||
|
||||
//! \brief Returns a serialized form of the map.
|
||||
|
@ -143,7 +143,7 @@ bool DeliverException(thread_t thread,
|
||||
thread_state_data_t new_state;
|
||||
size_t state_size =
|
||||
sizeof(natural_t) *
|
||||
std::min(state_count, static_cast<unsigned int>(THREAD_STATE_MAX));
|
||||
std::min(state_count, implicit_cast<unsigned int>(THREAD_STATE_MAX));
|
||||
memcpy(new_state, state, state_size);
|
||||
mach_msg_type_number_t new_state_count = THREAD_STATE_MAX;
|
||||
|
||||
@ -181,13 +181,13 @@ bool DeliverException(thread_t thread,
|
||||
void SimulateCrash(const NativeCPUContext* cpu_context) {
|
||||
#if defined(ARCH_CPU_X86)
|
||||
DCHECK_EQ(cpu_context->tsh.flavor,
|
||||
static_cast<thread_state_flavor_t>(x86_THREAD_STATE32));
|
||||
DCHECK_EQ(static_cast<mach_msg_type_number_t>(cpu_context->tsh.count),
|
||||
implicit_cast<thread_state_flavor_t>(x86_THREAD_STATE32));
|
||||
DCHECK_EQ(implicit_cast<mach_msg_type_number_t>(cpu_context->tsh.count),
|
||||
x86_THREAD_STATE32_COUNT);
|
||||
#elif defined(ARCH_CPU_X86_64)
|
||||
DCHECK_EQ(cpu_context->tsh.flavor,
|
||||
static_cast<thread_state_flavor_t>(x86_THREAD_STATE64));
|
||||
DCHECK_EQ(static_cast<mach_msg_type_number_t>(cpu_context->tsh.count),
|
||||
implicit_cast<thread_state_flavor_t>(x86_THREAD_STATE64));
|
||||
DCHECK_EQ(implicit_cast<mach_msg_type_number_t>(cpu_context->tsh.count),
|
||||
x86_THREAD_STATE64_COUNT);
|
||||
#endif
|
||||
|
||||
|
@ -124,11 +124,11 @@ class TestSimulateCrashMac final : public MachMultiprocess,
|
||||
reinterpret_cast<const x86_thread_state*>(old_state);
|
||||
switch (state->tsh.flavor) {
|
||||
case x86_THREAD_STATE32:
|
||||
EXPECT_EQ(static_cast<int>(x86_THREAD_STATE32_COUNT),
|
||||
EXPECT_EQ(implicit_cast<int>(x86_THREAD_STATE32_COUNT),
|
||||
state->tsh.count);
|
||||
break;
|
||||
case x86_THREAD_STATE64:
|
||||
EXPECT_EQ(static_cast<int>(x86_THREAD_STATE64_COUNT),
|
||||
EXPECT_EQ(implicit_cast<int>(x86_THREAD_STATE64_COUNT),
|
||||
state->tsh.count);
|
||||
break;
|
||||
default:
|
||||
@ -143,11 +143,11 @@ class TestSimulateCrashMac final : public MachMultiprocess,
|
||||
reinterpret_cast<const x86_float_state*>(old_state);
|
||||
switch (state->fsh.flavor) {
|
||||
case x86_FLOAT_STATE32:
|
||||
EXPECT_EQ(static_cast<int>(x86_FLOAT_STATE32_COUNT),
|
||||
EXPECT_EQ(implicit_cast<int>(x86_FLOAT_STATE32_COUNT),
|
||||
state->fsh.count);
|
||||
break;
|
||||
case x86_FLOAT_STATE64:
|
||||
EXPECT_EQ(static_cast<int>(x86_FLOAT_STATE64_COUNT),
|
||||
EXPECT_EQ(implicit_cast<int>(x86_FLOAT_STATE64_COUNT),
|
||||
state->fsh.count);
|
||||
break;
|
||||
default:
|
||||
@ -162,11 +162,11 @@ class TestSimulateCrashMac final : public MachMultiprocess,
|
||||
reinterpret_cast<const x86_debug_state*>(old_state);
|
||||
switch (state->dsh.flavor) {
|
||||
case x86_DEBUG_STATE32:
|
||||
EXPECT_EQ(static_cast<int>(x86_DEBUG_STATE32_COUNT),
|
||||
EXPECT_EQ(implicit_cast<int>(x86_DEBUG_STATE32_COUNT),
|
||||
state->dsh.count);
|
||||
break;
|
||||
case x86_DEBUG_STATE64:
|
||||
EXPECT_EQ(static_cast<int>(x86_DEBUG_STATE64_COUNT),
|
||||
EXPECT_EQ(implicit_cast<int>(x86_DEBUG_STATE64_COUNT),
|
||||
state->dsh.count);
|
||||
break;
|
||||
default:
|
||||
|
@ -293,9 +293,9 @@ void MinidumpModuleWriter::SetFileVersion(uint16_t version_0,
|
||||
DCHECK_EQ(state(), kStateMutable);
|
||||
|
||||
module_.VersionInfo.dwFileVersionMS =
|
||||
(static_cast<uint32_t>(version_0) << 16) | version_1;
|
||||
(implicit_cast<uint32_t>(version_0) << 16) | version_1;
|
||||
module_.VersionInfo.dwFileVersionLS =
|
||||
(static_cast<uint32_t>(version_2) << 16) | version_3;
|
||||
(implicit_cast<uint32_t>(version_2) << 16) | version_3;
|
||||
}
|
||||
|
||||
void MinidumpModuleWriter::SetProductVersion(uint16_t version_0,
|
||||
@ -305,9 +305,9 @@ void MinidumpModuleWriter::SetProductVersion(uint16_t version_0,
|
||||
DCHECK_EQ(state(), kStateMutable);
|
||||
|
||||
module_.VersionInfo.dwProductVersionMS =
|
||||
(static_cast<uint32_t>(version_0) << 16) | version_1;
|
||||
(implicit_cast<uint32_t>(version_0) << 16) | version_1;
|
||||
module_.VersionInfo.dwProductVersionLS =
|
||||
(static_cast<uint32_t>(version_2) << 16) | version_3;
|
||||
(implicit_cast<uint32_t>(version_2) << 16) | version_3;
|
||||
}
|
||||
|
||||
void MinidumpModuleWriter::SetFileFlagsAndMask(uint32_t file_flags,
|
||||
|
@ -119,7 +119,7 @@ void ExpectCodeViewRecord(const MINIDUMP_LOCATION_DESCRIPTOR* codeview_record,
|
||||
MinidumpModuleCodeViewRecordPDB20>(file_contents,
|
||||
*codeview_record);
|
||||
ASSERT_TRUE(codeview_pdb20_record);
|
||||
EXPECT_EQ(static_cast<uint32_t>(expected_pdb_timestamp),
|
||||
EXPECT_EQ(implicit_cast<uint32_t>(expected_pdb_timestamp),
|
||||
codeview_pdb20_record->timestamp);
|
||||
EXPECT_EQ(expected_pdb_age, codeview_pdb20_record->age);
|
||||
|
||||
@ -219,9 +219,9 @@ void ExpectModule(const MINIDUMP_MODULE* expected,
|
||||
EXPECT_EQ(expected->SizeOfImage, observed->SizeOfImage);
|
||||
EXPECT_EQ(expected->CheckSum, observed->CheckSum);
|
||||
EXPECT_EQ(expected->TimeDateStamp, observed->TimeDateStamp);
|
||||
EXPECT_EQ(static_cast<uint32_t>(VS_FFI_SIGNATURE),
|
||||
EXPECT_EQ(implicit_cast<uint32_t>(VS_FFI_SIGNATURE),
|
||||
observed->VersionInfo.dwSignature);
|
||||
EXPECT_EQ(static_cast<uint32_t>(VS_FFI_STRUCVERSION),
|
||||
EXPECT_EQ(implicit_cast<uint32_t>(VS_FFI_STRUCVERSION),
|
||||
observed->VersionInfo.dwStrucVersion);
|
||||
EXPECT_EQ(expected->VersionInfo.dwFileVersionMS,
|
||||
observed->VersionInfo.dwFileVersionMS);
|
||||
|
@ -34,12 +34,12 @@ uint64_t AMD64FeaturesFromSystemSnapshot(
|
||||
// x86_64. cmpxchg is supported on 486 and later.
|
||||
uint64_t minidump_features = ADD_FEATURE(PF_COMPARE_EXCHANGE_DOUBLE);
|
||||
|
||||
#define MAP_FEATURE(features, cpuid_bit, minidump_bit) \
|
||||
do { \
|
||||
if ((features) & (static_cast<decltype(features)>(1) << (cpuid_bit))) { \
|
||||
minidump_features |= ADD_FEATURE(minidump_bit); \
|
||||
} \
|
||||
} while (false)
|
||||
#define MAP_FEATURE(features, cpuid_bit, minidump_bit) \
|
||||
do { \
|
||||
if ((features) & (implicit_cast<decltype(features)>(1) << (cpuid_bit))) { \
|
||||
minidump_features |= ADD_FEATURE(minidump_bit); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define F_TSC 4
|
||||
#define F_PAE 6
|
||||
@ -128,8 +128,8 @@ void MinidumpSystemInfoWriter::InitializeFromSnapshot(
|
||||
SetCPUArchitecture(cpu_architecture);
|
||||
|
||||
uint32_t cpu_revision = system_snapshot->CPURevision();
|
||||
SetCPULevelAndRevision(
|
||||
(cpu_revision & 0xffff0000) >> 16, cpu_revision & 0x0000ffff);
|
||||
SetCPULevelAndRevision((cpu_revision & 0xffff0000) >> 16,
|
||||
cpu_revision & 0x0000ffff);
|
||||
SetCPUCount(system_snapshot->CPUCount());
|
||||
|
||||
if (cpu_architecture == kMinidumpCPUArchitectureX86) {
|
||||
|
@ -279,7 +279,7 @@ TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_X86) {
|
||||
const uint8_t kCPUStepping = 1;
|
||||
|
||||
const uint8_t kCPUBasicFamily =
|
||||
std::min(kCPUFamily, static_cast<uint16_t>(15));
|
||||
std::min(kCPUFamily, implicit_cast<uint16_t>(15));
|
||||
const uint8_t kCPUExtendedFamily = kCPUFamily - kCPUBasicFamily;
|
||||
|
||||
// These checks ensure that even if the constants above change, they represent
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/strings/string16.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -75,7 +76,8 @@ const IMAGE_DEBUG_MISC* MinidumpWritableAtLocationDescriptor<IMAGE_DEBUG_MISC>(
|
||||
}
|
||||
|
||||
if (misc->DataType != IMAGE_DEBUG_MISC_EXENAME) {
|
||||
EXPECT_EQ(static_cast<uint32_t>(IMAGE_DEBUG_MISC_EXENAME), misc->DataType);
|
||||
EXPECT_EQ(implicit_cast<uint32_t>(IMAGE_DEBUG_MISC_EXENAME),
|
||||
misc->DataType);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -123,11 +125,11 @@ const MINIDUMP_HEADER* MinidumpWritableAtLocationDescriptor<MINIDUMP_HEADER>(
|
||||
}
|
||||
|
||||
if (header->Signature != MINIDUMP_SIGNATURE) {
|
||||
EXPECT_EQ(static_cast<uint32_t>(MINIDUMP_SIGNATURE), header->Signature);
|
||||
EXPECT_EQ(implicit_cast<uint32_t>(MINIDUMP_SIGNATURE), header->Signature);
|
||||
return nullptr;
|
||||
}
|
||||
if (header->Version != MINIDUMP_VERSION) {
|
||||
EXPECT_EQ(static_cast<uint32_t>(MINIDUMP_VERSION), header->Version);
|
||||
EXPECT_EQ(implicit_cast<uint32_t>(MINIDUMP_VERSION), header->Version);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "snapshot/cpu_context.h"
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/logging.h"
|
||||
|
||||
namespace crashpad {
|
||||
@ -55,11 +56,11 @@ uint16_t CPUContextX86::FxsaveToFsaveTagWord(
|
||||
// The integer bit the “J bit”.
|
||||
bool integer_bit = st[7] & 0x80;
|
||||
if (exponent == 0) {
|
||||
uint64_t fraction = ((static_cast<uint64_t>(st[7]) & 0x7f) << 56) |
|
||||
(static_cast<uint64_t>(st[6]) << 48) |
|
||||
(static_cast<uint64_t>(st[5]) << 40) |
|
||||
(static_cast<uint64_t>(st[4]) << 32) |
|
||||
(static_cast<uint32_t>(st[3]) << 24) |
|
||||
uint64_t fraction = ((implicit_cast<uint64_t>(st[7]) & 0x7f) << 56) |
|
||||
(implicit_cast<uint64_t>(st[6]) << 48) |
|
||||
(implicit_cast<uint64_t>(st[5]) << 40) |
|
||||
(implicit_cast<uint64_t>(st[4]) << 32) |
|
||||
(implicit_cast<uint32_t>(st[3]) << 24) |
|
||||
(st[2] << 16) | (st[1] << 8) | st[0];
|
||||
if (!integer_bit && fraction == 0) {
|
||||
fsave_bits = kX87TagZero;
|
||||
|
@ -439,7 +439,7 @@ bool MachOImageReader::LookUpExternalDefinedSymbol(
|
||||
|
||||
uint32_t MachOImageReader::DylibVersion() const {
|
||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||
DCHECK_EQ(FileType(), static_cast<uint32_t>(MH_DYLIB));
|
||||
DCHECK_EQ(FileType(), implicit_cast<uint32_t>(MH_DYLIB));
|
||||
|
||||
if (id_dylib_command_) {
|
||||
return id_dylib_command_->dylib_current_version;
|
||||
|
@ -510,7 +510,7 @@ TEST(MachOImageReader, Self_MainExecutable) {
|
||||
ASSERT_TRUE(image_reader.Initialize(
|
||||
&process_reader, mh_execute_header_address, "executable"));
|
||||
|
||||
EXPECT_EQ(static_cast<uint32_t>(MH_EXECUTE), image_reader.FileType());
|
||||
EXPECT_EQ(implicit_cast<uint32_t>(MH_EXECUTE), image_reader.FileType());
|
||||
|
||||
// The main executable has image index 0.
|
||||
intptr_t image_slide = _dyld_get_image_vmaddr_slide(0);
|
||||
@ -556,7 +556,7 @@ TEST(MachOImageReader, Self_DyldImages) {
|
||||
|
||||
uint32_t file_type = image_reader.FileType();
|
||||
if (index == 0) {
|
||||
EXPECT_EQ(static_cast<uint32_t>(MH_EXECUTE), file_type);
|
||||
EXPECT_EQ(implicit_cast<uint32_t>(MH_EXECUTE), file_type);
|
||||
} else {
|
||||
EXPECT_TRUE(file_type == MH_DYLIB || file_type == MH_BUNDLE);
|
||||
}
|
||||
@ -588,7 +588,7 @@ TEST(MachOImageReader, Self_DyldImages) {
|
||||
ASSERT_TRUE(
|
||||
image_reader.Initialize(&process_reader, image_address, "dyld"));
|
||||
|
||||
EXPECT_EQ(static_cast<uint32_t>(MH_DYLINKER), image_reader.FileType());
|
||||
EXPECT_EQ(implicit_cast<uint32_t>(MH_DYLINKER), image_reader.FileType());
|
||||
|
||||
// There’s no good API to get dyld’s slide, so don’t bother checking it.
|
||||
ASSERT_NO_FATAL_FAILURE(ExpectMachImage(
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "util/mac/mac_util.h"
|
||||
@ -121,7 +122,7 @@ TEST(ProcessTypes, DyldImagesSelf) {
|
||||
proctype_image_infos.dyldVersion);
|
||||
EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_infos->errorMessage),
|
||||
proctype_image_infos.errorMessage);
|
||||
EXPECT_EQ(static_cast<uint64_t>(self_image_infos->terminationFlags),
|
||||
EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->terminationFlags),
|
||||
proctype_image_infos.terminationFlags);
|
||||
|
||||
TEST_STRING(
|
||||
@ -135,12 +136,12 @@ TEST(ProcessTypes, DyldImagesSelf) {
|
||||
proctype_image_infos.coreSymbolicationShmPage);
|
||||
}
|
||||
if (proctype_image_infos.version >= 7) {
|
||||
EXPECT_EQ(static_cast<uint64_t>(self_image_infos->systemOrderFlag),
|
||||
EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->systemOrderFlag),
|
||||
proctype_image_infos.systemOrderFlag);
|
||||
}
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
||||
if (proctype_image_infos.version >= 8) {
|
||||
EXPECT_EQ(static_cast<uint64_t>(self_image_infos->uuidArrayCount),
|
||||
EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->uuidArrayCount),
|
||||
proctype_image_infos.uuidArrayCount);
|
||||
}
|
||||
if (proctype_image_infos.version >= 9) {
|
||||
@ -149,11 +150,11 @@ TEST(ProcessTypes, DyldImagesSelf) {
|
||||
proctype_image_infos.dyldAllImageInfosAddress);
|
||||
}
|
||||
if (proctype_image_infos.version >= 10) {
|
||||
EXPECT_EQ(static_cast<uint64_t>(self_image_infos->initialImageCount),
|
||||
EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->initialImageCount),
|
||||
proctype_image_infos.initialImageCount);
|
||||
}
|
||||
if (proctype_image_infos.version >= 11) {
|
||||
EXPECT_EQ(static_cast<uint64_t>(self_image_infos->errorKind),
|
||||
EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->errorKind),
|
||||
proctype_image_infos.errorKind);
|
||||
EXPECT_EQ(
|
||||
reinterpret_cast<uint64_t>(self_image_infos->errorClientOfDylibPath),
|
||||
@ -176,7 +177,7 @@ TEST(ProcessTypes, DyldImagesSelf) {
|
||||
process_reader, self_image_infos, proctype_image_infos, errorSymbol);
|
||||
}
|
||||
if (proctype_image_infos.version >= 12) {
|
||||
EXPECT_EQ(static_cast<uint64_t>(self_image_infos->sharedCacheSlide),
|
||||
EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->sharedCacheSlide),
|
||||
proctype_image_infos.sharedCacheSlide);
|
||||
}
|
||||
#endif
|
||||
@ -190,7 +191,7 @@ TEST(ProcessTypes, DyldImagesSelf) {
|
||||
if (proctype_image_infos.version >= 14) {
|
||||
for (size_t index = 0; index < arraysize(self_image_infos->reserved);
|
||||
++index) {
|
||||
EXPECT_EQ(static_cast<uint64_t>(self_image_infos->reserved[index]),
|
||||
EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->reserved[index]),
|
||||
proctype_image_infos.reserved[index])
|
||||
<< "index " << index;
|
||||
}
|
||||
@ -219,7 +220,7 @@ TEST(ProcessTypes, DyldImagesSelf) {
|
||||
EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_info->imageFilePath),
|
||||
proctype_image_info.imageFilePath)
|
||||
<< "index " << index;
|
||||
EXPECT_EQ(static_cast<uint64_t>(self_image_info->imageFileModDate),
|
||||
EXPECT_EQ(implicit_cast<uint64_t>(self_image_info->imageFileModDate),
|
||||
proctype_image_info.imageFileModDate)
|
||||
<< "index " << index;
|
||||
|
||||
|
@ -93,7 +93,7 @@ bool FileWriter::WriteIoVec(std::vector<WritableIoVec>* iovecs) {
|
||||
|
||||
while (size > 0) {
|
||||
size_t writev_iovec_count =
|
||||
std::min(remaining_iovecs, static_cast<size_t>(IOV_MAX));
|
||||
std::min(remaining_iovecs, implicit_cast<size_t>(IOV_MAX));
|
||||
ssize_t written = HANDLE_EINTR(writev(fd_.get(), iov, writev_iovec_count));
|
||||
if (written < 0) {
|
||||
PLOG(ERROR) << "writev";
|
||||
@ -113,7 +113,7 @@ bool FileWriter::WriteIoVec(std::vector<WritableIoVec>* iovecs) {
|
||||
|
||||
while (written > 0) {
|
||||
size_t wrote_this_iovec =
|
||||
std::min(static_cast<size_t>(written), iov->iov_len);
|
||||
std::min(implicit_cast<size_t>(written), iov->iov_len);
|
||||
written -= wrote_this_iovec;
|
||||
if (wrote_this_iovec < iov->iov_len) {
|
||||
iov->iov_base =
|
||||
|
@ -101,13 +101,13 @@ TEST(StringFileWriter, WriteInvalid) {
|
||||
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
|
||||
|
||||
EXPECT_FALSE(writer.Write(
|
||||
"", static_cast<size_t>(std::numeric_limits<ssize_t>::max()) + 1));
|
||||
"", implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()) + 1));
|
||||
EXPECT_TRUE(writer.string().empty());
|
||||
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
|
||||
|
||||
EXPECT_TRUE(writer.Write("a", 1));
|
||||
EXPECT_FALSE(writer.Write(
|
||||
"", static_cast<size_t>(std::numeric_limits<ssize_t>::max())));
|
||||
"", implicit_cast<size_t>(std::numeric_limits<ssize_t>::max())));
|
||||
EXPECT_EQ(1u, writer.string().size());
|
||||
EXPECT_EQ("a", writer.string());
|
||||
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
|
||||
@ -363,8 +363,8 @@ TEST(StringFileWriter, SeekInvalid) {
|
||||
EXPECT_TRUE(writer.string().empty());
|
||||
|
||||
const off_t kMaxOffset =
|
||||
std::min(static_cast<uint64_t>(std::numeric_limits<off_t>::max()),
|
||||
static_cast<uint64_t>(std::numeric_limits<size_t>::max()));
|
||||
std::min(implicit_cast<uint64_t>(std::numeric_limits<off_t>::max()),
|
||||
implicit_cast<uint64_t>(std::numeric_limits<size_t>::max()));
|
||||
|
||||
EXPECT_EQ(kMaxOffset, writer.Seek(kMaxOffset, SEEK_SET));
|
||||
EXPECT_EQ(kMaxOffset, writer.Seek(0, SEEK_CUR));
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/mac/foundation_util.h"
|
||||
#include "base/mac/scoped_launch_data.h"
|
||||
#include "base/mac/scoped_cftyperef.h"
|
||||
@ -44,7 +45,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) {
|
||||
}
|
||||
|
||||
CFPropertyListRef value_cf =
|
||||
static_cast<CFPropertyListRef>([dictionary_ns objectForKey:key]);
|
||||
implicit_cast<CFPropertyListRef>([dictionary_ns objectForKey:key]);
|
||||
launch_data_t value_launch = CFPropertyToLaunchData(value_cf);
|
||||
if (!value_launch) {
|
||||
return nullptr;
|
||||
@ -65,7 +66,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) {
|
||||
|
||||
for (id element_ns in array_ns) {
|
||||
CFPropertyListRef element_cf =
|
||||
static_cast<CFPropertyListRef>(element_ns);
|
||||
implicit_cast<CFPropertyListRef>(element_ns);
|
||||
launch_data_t element_launch = CFPropertyToLaunchData(element_cf);
|
||||
if (!element_launch) {
|
||||
return nullptr;
|
||||
|
@ -80,8 +80,8 @@ class TestExcClientVariants : public UniversalMachExcServer,
|
||||
mach_exception_code_t expect_code = exception_code_;
|
||||
mach_exception_subcode_t expect_subcode = exception_subcode_;
|
||||
if ((behavior & MACH_EXCEPTION_CODES) == 0) {
|
||||
expect_code = static_cast<exception_data_type_t>(expect_code);
|
||||
expect_subcode = static_cast<exception_data_type_t>(expect_subcode);
|
||||
expect_code = implicit_cast<exception_data_type_t>(expect_code);
|
||||
expect_subcode = implicit_cast<exception_data_type_t>(expect_subcode);
|
||||
}
|
||||
|
||||
EXPECT_EQ(exception_, exception);
|
||||
@ -101,7 +101,7 @@ class TestExcClientVariants : public UniversalMachExcServer,
|
||||
EXPECT_EQ(exception_ + 10, *flavor);
|
||||
EXPECT_EQ(MACHINE_THREAD_STATE_COUNT, old_state_count);
|
||||
EXPECT_NE(nullptr, old_state);
|
||||
EXPECT_EQ(static_cast<mach_msg_type_number_t>(THREAD_STATE_MAX),
|
||||
EXPECT_EQ(implicit_cast<mach_msg_type_number_t>(THREAD_STATE_MAX),
|
||||
*new_state_count);
|
||||
EXPECT_NE(nullptr, new_state);
|
||||
|
||||
|
@ -51,12 +51,12 @@ const exception_type_t kExceptionType = EXC_BAD_ACCESS;
|
||||
// promoted to the wider mach_exception_data_type_t type as a signed quantity.
|
||||
const exception_data_type_t kTestExceptonCodes[] = {
|
||||
KERN_PROTECTION_FAILURE,
|
||||
static_cast<exception_data_type_t>(0xfedcba98),
|
||||
implicit_cast<exception_data_type_t>(0xfedcba98),
|
||||
};
|
||||
|
||||
const mach_exception_data_type_t kTestMachExceptionCodes[] = {
|
||||
KERN_PROTECTION_FAILURE,
|
||||
static_cast<mach_exception_data_type_t>(0xfedcba9876543210),
|
||||
implicit_cast<mach_exception_data_type_t>(0xfedcba9876543210),
|
||||
};
|
||||
|
||||
const thread_state_flavor_t kThreadStateFlavor = MACHINE_THREAD_STATE;
|
||||
@ -122,7 +122,7 @@ struct __attribute__((packed, aligned(4))) ExceptionRaiseReply {
|
||||
// MachExceptionRaiseReply. Knowing which behavior is expected allows the
|
||||
// message ID to be checked.
|
||||
void Verify(exception_behavior_t behavior) {
|
||||
EXPECT_EQ(static_cast<mach_msg_bits_t>(
|
||||
EXPECT_EQ(implicit_cast<mach_msg_bits_t>(
|
||||
MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0)),
|
||||
Head.msgh_bits);
|
||||
EXPECT_EQ(sizeof(*this), Head.msgh_size);
|
||||
@ -196,7 +196,7 @@ struct __attribute__((packed, aligned(4))) ExceptionRaiseStateReply {
|
||||
// MachExceptionRaiseStateIdentityReply. Knowing which behavior is expected
|
||||
// allows the message ID to be checked.
|
||||
void Verify(exception_behavior_t behavior) {
|
||||
EXPECT_EQ(static_cast<mach_msg_bits_t>(
|
||||
EXPECT_EQ(implicit_cast<mach_msg_bits_t>(
|
||||
MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0)),
|
||||
Head.msgh_bits);
|
||||
EXPECT_EQ(sizeof(*this), Head.msgh_size);
|
||||
@ -409,7 +409,7 @@ struct __attribute__((packed, aligned(4))) BadIDErrorReply
|
||||
}
|
||||
|
||||
void Verify(mach_msg_id_t id) {
|
||||
EXPECT_EQ(static_cast<mach_msg_bits_t>(
|
||||
EXPECT_EQ(implicit_cast<mach_msg_bits_t>(
|
||||
MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0)),
|
||||
Head.msgh_bits);
|
||||
EXPECT_EQ(sizeof(*this), Head.msgh_size);
|
||||
@ -923,7 +923,7 @@ class TestExcServerVariants : public UniversalMachExcServer,
|
||||
EXPECT_EQ(flavor_, *flavor);
|
||||
EXPECT_EQ(state_count_, old_state_count);
|
||||
EXPECT_NE(nullptr, old_state);
|
||||
EXPECT_EQ(static_cast<mach_msg_type_number_t>(THREAD_STATE_MAX),
|
||||
EXPECT_EQ(implicit_cast<mach_msg_type_number_t>(THREAD_STATE_MAX),
|
||||
*new_state_count);
|
||||
EXPECT_NE(nullptr, new_state);
|
||||
} else {
|
||||
|
@ -23,8 +23,8 @@ namespace crashpad {
|
||||
//! `mach_port_t`.
|
||||
//!
|
||||
//! For situations where implicit conversions between signed and unsigned types
|
||||
//! are not performed, use kMachPortNull instead of an explicit `static_cast` of
|
||||
//! `MACH_PORT_NULL` to `mach_port_t`. This is useful for logging and testing
|
||||
//! are not performed, use kMachPortNull instead of an explicit `implicit_cast`
|
||||
//! of `MACH_PORT_NULL` to `mach_port_t`. This is useful for logging and testing
|
||||
//! assertions.
|
||||
const mach_port_t kMachPortNull = MACH_PORT_NULL;
|
||||
|
||||
|
@ -95,7 +95,7 @@ mach_msg_return_t MachMessageServer::Run(Interface* interface,
|
||||
} else if (timeout_ms != MACH_MSG_TIMEOUT_NONE) {
|
||||
options |= timeout_options;
|
||||
deadline = ClockMonotonicNanoseconds() +
|
||||
static_cast<uint64_t>(timeout_ms) * kNanosecondsPerMillisecond;
|
||||
implicit_cast<uint64_t>(timeout_ms) * kNanosecondsPerMillisecond;
|
||||
} else {
|
||||
options &= ~timeout_options;
|
||||
deadline = 0;
|
||||
|
@ -224,10 +224,10 @@ class TestMachMessageServer : public MachMessageServer::Interface,
|
||||
EXPECT_EQ(1u, request->body.msgh_descriptor_count);
|
||||
EXPECT_NE(kMachPortNull, request->port_descriptor.name);
|
||||
parent_complex_message_port_ = request->port_descriptor.name;
|
||||
EXPECT_EQ(static_cast<mach_msg_type_name_t>(MACH_MSG_TYPE_MOVE_SEND),
|
||||
EXPECT_EQ(implicit_cast<mach_msg_type_name_t>(MACH_MSG_TYPE_MOVE_SEND),
|
||||
request->port_descriptor.disposition);
|
||||
EXPECT_EQ(
|
||||
static_cast<mach_msg_descriptor_type_t>(MACH_MSG_PORT_DESCRIPTOR),
|
||||
implicit_cast<mach_msg_descriptor_type_t>(MACH_MSG_PORT_DESCRIPTOR),
|
||||
request->port_descriptor.type);
|
||||
} else {
|
||||
EXPECT_EQ(0u, request->body.msgh_descriptor_count);
|
||||
@ -252,7 +252,7 @@ class TestMachMessageServer : public MachMessageServer::Interface,
|
||||
trailer = &request->trailer;
|
||||
}
|
||||
|
||||
EXPECT_EQ(static_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0),
|
||||
EXPECT_EQ(implicit_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0),
|
||||
trailer->msgh_trailer_type);
|
||||
EXPECT_EQ(MACH_MSG_TRAILER_MINIMUM_SIZE, trailer->msgh_trailer_size);
|
||||
|
||||
@ -525,7 +525,7 @@ class TestMachMessageServer : public MachMessageServer::Interface,
|
||||
MACH_PORT_NULL);
|
||||
ASSERT_EQ(MACH_MSG_SUCCESS, kr) << MachErrorMessage(kr, "mach_msg");
|
||||
|
||||
ASSERT_EQ(static_cast<mach_msg_bits_t>(
|
||||
ASSERT_EQ(implicit_cast<mach_msg_bits_t>(
|
||||
MACH_MSGH_BITS(0, MACH_MSG_TYPE_MOVE_SEND)), reply.Head.msgh_bits);
|
||||
ASSERT_EQ(sizeof(ReplyMessage), reply.Head.msgh_size);
|
||||
ASSERT_EQ(kMachPortNull, reply.Head.msgh_remote_port);
|
||||
@ -534,7 +534,7 @@ class TestMachMessageServer : public MachMessageServer::Interface,
|
||||
ASSERT_EQ(0, memcmp(&reply.NDR, &NDR_record, sizeof(NDR_record)));
|
||||
ASSERT_EQ(options_.server_mig_retcode, reply.RetCode);
|
||||
ASSERT_EQ(replies_, reply.number);
|
||||
ASSERT_EQ(static_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0),
|
||||
ASSERT_EQ(implicit_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0),
|
||||
reply.trailer.msgh_trailer_type);
|
||||
ASSERT_EQ(MACH_MSG_TRAILER_MINIMUM_SIZE, reply.trailer.msgh_trailer_size);
|
||||
|
||||
|
@ -192,7 +192,7 @@ namespace crashpad {
|
||||
std::string ExceptionToString(exception_type_t exception,
|
||||
SymbolicConstantToStringOptions options) {
|
||||
const char* exception_name =
|
||||
static_cast<size_t>(exception) < arraysize(kExceptionNames)
|
||||
implicit_cast<size_t>(exception) < arraysize(kExceptionNames)
|
||||
? kExceptionNames[exception]
|
||||
: nullptr;
|
||||
if (!exception_name) {
|
||||
@ -218,7 +218,7 @@ bool StringToException(const base::StringPiece& string,
|
||||
base::StringPiece short_string =
|
||||
can_match_full ? string.substr(strlen(kExcPrefix)) : string;
|
||||
for (exception_type_t index = 0;
|
||||
index < static_cast<exception_type_t>(arraysize(kExceptionNames));
|
||||
index < implicit_cast<exception_type_t>(arraysize(kExceptionNames));
|
||||
++index) {
|
||||
const char* exception_name = kExceptionNames[index];
|
||||
if (!exception_name) {
|
||||
@ -322,7 +322,7 @@ bool StringToExceptionMask(const base::StringPiece& string,
|
||||
base::StringPiece short_string =
|
||||
can_match_full ? string.substr(strlen(kExcMaskPrefix)) : string;
|
||||
for (exception_type_t index = 0;
|
||||
index < static_cast<exception_type_t>(arraysize(kExceptionNames));
|
||||
index < implicit_cast<exception_type_t>(arraysize(kExceptionNames));
|
||||
++index) {
|
||||
const char* exception_name = kExceptionNames[index];
|
||||
if (!exception_name) {
|
||||
@ -361,7 +361,7 @@ std::string ExceptionBehaviorToString(exception_behavior_t behavior,
|
||||
const exception_behavior_t basic_behavior = ExceptionBehaviorBasic(behavior);
|
||||
|
||||
const char* behavior_name =
|
||||
static_cast<size_t>(basic_behavior) < arraysize(kBehaviorNames)
|
||||
implicit_cast<size_t>(basic_behavior) < arraysize(kBehaviorNames)
|
||||
? kBehaviorNames[basic_behavior]
|
||||
: nullptr;
|
||||
if (!behavior_name) {
|
||||
@ -428,7 +428,7 @@ bool StringToExceptionBehavior(const base::StringPiece& string,
|
||||
base::StringPiece short_string =
|
||||
can_match_full ? sp.substr(strlen(kBehaviorPrefix)) : sp;
|
||||
for (exception_behavior_t index = 0;
|
||||
index < static_cast<exception_behavior_t>(arraysize(kBehaviorNames));
|
||||
index < implicit_cast<exception_behavior_t>(arraysize(kBehaviorNames));
|
||||
++index) {
|
||||
const char* behavior_name = kBehaviorNames[index];
|
||||
if (!behavior_name) {
|
||||
@ -463,7 +463,7 @@ bool StringToExceptionBehavior(const base::StringPiece& string,
|
||||
std::string ThreadStateFlavorToString(thread_state_flavor_t flavor,
|
||||
SymbolicConstantToStringOptions options) {
|
||||
const char* flavor_name =
|
||||
static_cast<size_t>(flavor) < arraysize(kFlavorNames)
|
||||
implicit_cast<size_t>(flavor) < arraysize(kFlavorNames)
|
||||
? kFlavorNames[flavor]
|
||||
: nullptr;
|
||||
|
||||
@ -496,7 +496,7 @@ bool StringToThreadStateFlavor(const base::StringPiece& string,
|
||||
thread_state_flavor_t* flavor) {
|
||||
if ((options & kAllowFullName) || (options & kAllowShortName)) {
|
||||
for (thread_state_flavor_t index = 0;
|
||||
index < static_cast<thread_state_flavor_t>(arraysize(kFlavorNames));
|
||||
index < implicit_cast<thread_state_flavor_t>(arraysize(kFlavorNames));
|
||||
++index) {
|
||||
const char* flavor_name = kFlavorNames[index];
|
||||
if (!flavor_name) {
|
||||
|
@ -537,16 +537,16 @@ const struct {
|
||||
{EXCEPTION_DEFAULT, "EXCEPTION_DEFAULT", "DEFAULT"},
|
||||
{EXCEPTION_STATE, "EXCEPTION_STATE", "STATE"},
|
||||
{EXCEPTION_STATE_IDENTITY, "EXCEPTION_STATE_IDENTITY", "STATE_IDENTITY"},
|
||||
{static_cast<exception_behavior_t>(EXCEPTION_DEFAULT |
|
||||
MACH_EXCEPTION_CODES),
|
||||
{implicit_cast<exception_behavior_t>(EXCEPTION_DEFAULT |
|
||||
MACH_EXCEPTION_CODES),
|
||||
"EXCEPTION_DEFAULT|MACH_EXCEPTION_CODES",
|
||||
"DEFAULT|MACH"},
|
||||
{static_cast<exception_behavior_t>(EXCEPTION_STATE |
|
||||
MACH_EXCEPTION_CODES),
|
||||
{implicit_cast<exception_behavior_t>(EXCEPTION_STATE |
|
||||
MACH_EXCEPTION_CODES),
|
||||
"EXCEPTION_STATE|MACH_EXCEPTION_CODES",
|
||||
"STATE|MACH"},
|
||||
{static_cast<exception_behavior_t>(EXCEPTION_STATE_IDENTITY |
|
||||
MACH_EXCEPTION_CODES),
|
||||
{implicit_cast<exception_behavior_t>(EXCEPTION_STATE_IDENTITY |
|
||||
MACH_EXCEPTION_CODES),
|
||||
"EXCEPTION_STATE_IDENTITY|MACH_EXCEPTION_CODES",
|
||||
"STATE_IDENTITY|MACH"},
|
||||
};
|
||||
@ -699,26 +699,26 @@ TEST(SymbolicConstantsMach, StringToExceptionBehavior) {
|
||||
} kNonCanonicalTestData[] = {
|
||||
{"MACH_EXCEPTION_CODES|EXCEPTION_STATE_IDENTITY",
|
||||
kAllowFullName,
|
||||
static_cast<exception_behavior_t>(EXCEPTION_STATE_IDENTITY |
|
||||
MACH_EXCEPTION_CODES)},
|
||||
implicit_cast<exception_behavior_t>(EXCEPTION_STATE_IDENTITY |
|
||||
MACH_EXCEPTION_CODES)},
|
||||
{"MACH|STATE_IDENTITY",
|
||||
kAllowShortName,
|
||||
static_cast<exception_behavior_t>(EXCEPTION_STATE_IDENTITY |
|
||||
MACH_EXCEPTION_CODES)},
|
||||
implicit_cast<exception_behavior_t>(EXCEPTION_STATE_IDENTITY |
|
||||
MACH_EXCEPTION_CODES)},
|
||||
{"MACH_EXCEPTION_CODES|STATE",
|
||||
kAllowFullName | kAllowShortName,
|
||||
static_cast<exception_behavior_t>(EXCEPTION_STATE |
|
||||
MACH_EXCEPTION_CODES)},
|
||||
implicit_cast<exception_behavior_t>(EXCEPTION_STATE |
|
||||
MACH_EXCEPTION_CODES)},
|
||||
{"MACH|EXCEPTION_STATE",
|
||||
kAllowFullName | kAllowShortName,
|
||||
static_cast<exception_behavior_t>(EXCEPTION_STATE |
|
||||
MACH_EXCEPTION_CODES)},
|
||||
implicit_cast<exception_behavior_t>(EXCEPTION_STATE |
|
||||
MACH_EXCEPTION_CODES)},
|
||||
{"3|MACH_EXCEPTION_CODES",
|
||||
kAllowFullName | kAllowNumber,
|
||||
static_cast<exception_behavior_t>(MACH_EXCEPTION_CODES | 3)},
|
||||
implicit_cast<exception_behavior_t>(MACH_EXCEPTION_CODES | 3)},
|
||||
{"MACH|0x2",
|
||||
kAllowShortName | kAllowNumber,
|
||||
static_cast<exception_behavior_t>(MACH_EXCEPTION_CODES | 0x2)},
|
||||
implicit_cast<exception_behavior_t>(MACH_EXCEPTION_CODES | 0x2)},
|
||||
};
|
||||
|
||||
for (size_t index = 0; index < arraysize(kNonCanonicalTestData); ++index) {
|
||||
|
@ -69,13 +69,13 @@ TEST(Clock, SleepNanoseconds) {
|
||||
const uint64_t kTestData[] = {
|
||||
0,
|
||||
1,
|
||||
static_cast<uint64_t>(1E3), // 1 microsecond
|
||||
static_cast<uint64_t>(1E4), // 10 microseconds
|
||||
static_cast<uint64_t>(1E5), // 100 microseconds
|
||||
static_cast<uint64_t>(1E6), // 1 millisecond
|
||||
static_cast<uint64_t>(1E7), // 10 milliseconds
|
||||
static_cast<uint64_t>(2E7), // 20 milliseconds
|
||||
static_cast<uint64_t>(5E7), // 50 milliseconds
|
||||
implicit_cast<uint64_t>(1E3), // 1 microsecond
|
||||
implicit_cast<uint64_t>(1E4), // 10 microseconds
|
||||
implicit_cast<uint64_t>(1E5), // 100 microseconds
|
||||
implicit_cast<uint64_t>(1E6), // 1 millisecond
|
||||
implicit_cast<uint64_t>(1E7), // 10 milliseconds
|
||||
implicit_cast<uint64_t>(2E7), // 20 milliseconds
|
||||
implicit_cast<uint64_t>(5E7), // 50 milliseconds
|
||||
};
|
||||
|
||||
for (size_t index = 0; index < arraysize(kTestData); ++index) {
|
||||
|
@ -43,7 +43,7 @@ ssize_t StringHTTPBodyStream::GetBytesBuffer(uint8_t* buffer, size_t max_len) {
|
||||
|
||||
size_t num_bytes_returned =
|
||||
std::min(std::min(num_bytes_remaining, max_len),
|
||||
static_cast<size_t>(std::numeric_limits<ssize_t>::max()));
|
||||
implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()));
|
||||
memcpy(buffer, &string_[bytes_read_], num_bytes_returned);
|
||||
bytes_read_ += num_bytes_returned;
|
||||
return num_bytes_returned;
|
||||
|
@ -46,7 +46,7 @@ TEST(StringHTTPBodyStream, SmallString) {
|
||||
|
||||
std::string string("Hello, world");
|
||||
StringHTTPBodyStream stream(string);
|
||||
EXPECT_EQ(static_cast<ssize_t>(string.length()),
|
||||
EXPECT_EQ(implicit_cast<ssize_t>(string.length()),
|
||||
stream.GetBytesBuffer(buf, sizeof(buf)));
|
||||
|
||||
std::string actual(reinterpret_cast<const char*>(buf), string.length());
|
||||
|
@ -174,7 +174,7 @@ bool HTTPTransportMac::ExecuteSynchronously() {
|
||||
NSInteger http_status = [http_response statusCode];
|
||||
if (http_status != 200) {
|
||||
LOG(ERROR) << base::StringPrintf("HTTP status %ld",
|
||||
static_cast<long>(http_status));
|
||||
implicit_cast<long>(http_status));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ class CheckedRange {
|
||||
return false;
|
||||
}
|
||||
base::CheckedNumeric<ValueType> checked_end(base_);
|
||||
checked_end += static_cast<ValueType>(size_);
|
||||
checked_end += implicit_cast<ValueType>(size_);
|
||||
return checked_end.IsValid();
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,8 @@ TEST(InRangeCast, Int32) {
|
||||
EXPECT_EQ(1, InRangeCast<int32_t>(INT64_C(0x100000000), 1));
|
||||
EXPECT_EQ(kInt32Min, InRangeCast<int32_t>(kInt32Min, 1));
|
||||
EXPECT_EQ(kInt32Min,
|
||||
InRangeCast<int32_t>(static_cast<int64_t>(kInt32Min), 1));
|
||||
EXPECT_EQ(1, InRangeCast<int32_t>(static_cast<int64_t>(kInt32Min) - 1, 1));
|
||||
InRangeCast<int32_t>(implicit_cast<int64_t>(kInt32Min), 1));
|
||||
EXPECT_EQ(1, InRangeCast<int32_t>(implicit_cast<int64_t>(kInt32Min) - 1, 1));
|
||||
EXPECT_EQ(0, InRangeCast<int32_t>(0xffffffffu, 0));
|
||||
EXPECT_EQ(-1, InRangeCast<int32_t>(0xffffffffu, -1));
|
||||
EXPECT_EQ(kInt32Min, InRangeCast<int32_t>(0xffffffffu, kInt32Min));
|
||||
@ -104,7 +104,7 @@ TEST(InRangeCast, Int64) {
|
||||
EXPECT_EQ(1, InRangeCast<int64_t>(UINT64_C(0xffffffffffffffff), 1));
|
||||
EXPECT_EQ(kInt32Min, InRangeCast<int64_t>(kInt32Min, 1));
|
||||
EXPECT_EQ(kInt32Min,
|
||||
InRangeCast<int64_t>(static_cast<int64_t>(kInt32Min), 1));
|
||||
InRangeCast<int64_t>(implicit_cast<int64_t>(kInt32Min), 1));
|
||||
EXPECT_EQ(0, InRangeCast<int64_t>(UINT64_C(0xffffffffffffffff), 0));
|
||||
EXPECT_EQ(-1, InRangeCast<int64_t>(UINT64_C(0xffffffffffffffff), -1));
|
||||
EXPECT_EQ(kInt64Min,
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace crashpad {
|
||||
@ -33,7 +34,7 @@ TEST(ProcessUtil, ProcessArgumentsForPID) {
|
||||
// gtest argv processing scrambles argv, but it leaves argc and argv[0]
|
||||
// intact, so test those.
|
||||
|
||||
int argc = static_cast<int>(argv.size());
|
||||
int argc = implicit_cast<int>(argv.size());
|
||||
int expect_argc = *_NSGetArgc();
|
||||
EXPECT_EQ(expect_argc, argc);
|
||||
|
||||
|
@ -113,7 +113,7 @@ namespace crashpad {
|
||||
std::string SignalToString(int signal,
|
||||
SymbolicConstantToStringOptions options) {
|
||||
const char* signal_name =
|
||||
static_cast<size_t>(signal) < arraysize(kSignalNames)
|
||||
implicit_cast<size_t>(signal) < arraysize(kSignalNames)
|
||||
? kSignalNames[signal]
|
||||
: nullptr;
|
||||
if (!signal_name) {
|
||||
@ -139,7 +139,7 @@ bool StringToSignal(const base::StringPiece& string,
|
||||
base::StringPiece short_string =
|
||||
can_match_full ? string.substr(strlen(kSigPrefix)) : string;
|
||||
for (int index = 0;
|
||||
index < static_cast<int>(arraysize(kSignalNames));
|
||||
index < implicit_cast<int>(arraysize(kSignalNames));
|
||||
++index) {
|
||||
const char* signal_name = kSignalNames[index];
|
||||
if (!signal_name) {
|
||||
|
@ -139,11 +139,11 @@ void MachMultiprocess::MultiprocessParent() {
|
||||
ASSERT_EQ(sizeof(SendHelloMessage), message.header.msgh_size);
|
||||
EXPECT_EQ(info_->local_port, message.header.msgh_local_port);
|
||||
ASSERT_EQ(1u, message.body.msgh_descriptor_count);
|
||||
EXPECT_EQ(static_cast<mach_msg_type_name_t>(MACH_MSG_TYPE_MOVE_SEND),
|
||||
EXPECT_EQ(implicit_cast<mach_msg_type_name_t>(MACH_MSG_TYPE_MOVE_SEND),
|
||||
message.port_descriptor.disposition);
|
||||
ASSERT_EQ(static_cast<mach_msg_descriptor_type_t>(MACH_MSG_PORT_DESCRIPTOR),
|
||||
ASSERT_EQ(implicit_cast<mach_msg_descriptor_type_t>(MACH_MSG_PORT_DESCRIPTOR),
|
||||
message.port_descriptor.type);
|
||||
ASSERT_EQ(static_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0),
|
||||
ASSERT_EQ(implicit_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0),
|
||||
message.audit_trailer.msgh_trailer_type);
|
||||
ASSERT_EQ(sizeof(message.audit_trailer),
|
||||
message.audit_trailer.msgh_trailer_size);
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/posix/eintr_wrapper.h"
|
||||
@ -144,7 +145,7 @@ void CloseMultipleNowOrOnExec(int fd, int preserve_fd) {
|
||||
// Libc-997.90.3/gen/FreeBSD/sysconf.c sysconf() and 10.9.4
|
||||
// xnu-2422.110.17/bsd/kern/kern_descrip.c getdtablesize(), which both return
|
||||
// the current RLIMIT_NOFILE value, not the maximum possible file descriptor.
|
||||
int max_fd = std::max(static_cast<int>(sysconf(_SC_OPEN_MAX)), OPEN_MAX);
|
||||
int max_fd = std::max(implicit_cast<int>(sysconf(_SC_OPEN_MAX)), OPEN_MAX);
|
||||
max_fd = std::max(max_fd, getdtablesize());
|
||||
|
||||
for (int entry_fd = fd; entry_fd < max_fd; ++entry_fd) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user