diff --git a/client/crash_report_database_win.cc b/client/crash_report_database_win.cc index d0d0f2f8..84ed6e22 100644 --- a/client/crash_report_database_win.cc +++ b/client/crash_report_database_win.cc @@ -390,7 +390,7 @@ void Metadata::Read() { base::CheckedNumeric records_size = base::CheckedNumeric(header.num_records) * - sizeof(MetadataFileReportRecord); + static_cast(sizeof(MetadataFileReportRecord)); if (!records_size.IsValid()) { LOG(ERROR) << "record size out of range"; return; diff --git a/compat/win/sys/types.h b/compat/win/sys/types.h index 40344c2a..6cd8ab3d 100644 --- a/compat/win/sys/types.h +++ b/compat/win/sys/types.h @@ -18,12 +18,15 @@ // This is intended to be roughly equivalent to #include_next. #include <../include/sys/types.h> +#include + #ifdef _WIN64 -typedef __int64 ssize_t; +typedef int64_t ssize_t; +typedef uint64_t pid_t; #else typedef __w64 int ssize_t; +typedef __w64 unsigned int pid_t; #endif -typedef unsigned long pid_t; #endif // CRASHPAD_COMPAT_WIN_SYS_TYPES_H_ diff --git a/minidump/minidump_exception_writer.cc b/minidump/minidump_exception_writer.cc index 87382b22..3d0c3414 100644 --- a/minidump/minidump_exception_writer.cc +++ b/minidump/minidump_exception_writer.cc @@ -17,6 +17,7 @@ #include #include "base/logging.h" +#include "base/numerics/safe_conversions.h" #include "minidump/minidump_context_writer.h" #include "snapshot/exception_snapshot.h" #include "util/file/file_writer.h" @@ -66,7 +67,8 @@ void MinidumpExceptionWriter::SetExceptionInformation( arraysize(exception_.ExceptionRecord.ExceptionInformation); CHECK_LE(parameters, kMaxParameters); - exception_.ExceptionRecord.NumberParameters = parameters; + exception_.ExceptionRecord.NumberParameters = + base::checked_cast(parameters); size_t parameter = 0; for (; parameter < parameters; ++parameter) { exception_.ExceptionRecord.ExceptionInformation[parameter] = diff --git a/minidump/minidump_exception_writer_test.cc b/minidump/minidump_exception_writer_test.cc index 7309e469..a0866ba0 100644 --- a/minidump/minidump_exception_writer_test.cc +++ b/minidump/minidump_exception_writer_test.cc @@ -181,7 +181,7 @@ TEST(MinidumpExceptionWriter, Standard) { expected_exception_stream.ExceptionRecord.ExceptionAddress = kExceptionAddress; expected_exception_stream.ExceptionRecord.NumberParameters = - exception_information.size(); + static_cast(exception_information.size()); for (size_t index = 0; index < exception_information.size(); ++index) { expected_exception_stream.ExceptionRecord.ExceptionInformation[index] = exception_information[index]; @@ -209,7 +209,8 @@ TEST(MinidumpExceptionWriter, InitializeFromSnapshot) { expect_exception.ExceptionRecord.ExceptionCode = 100; expect_exception.ExceptionRecord.ExceptionFlags = 1; expect_exception.ExceptionRecord.ExceptionAddress = 0xfedcba9876543210; - expect_exception.ExceptionRecord.NumberParameters = exception_codes.size(); + expect_exception.ExceptionRecord.NumberParameters = + static_cast(exception_codes.size()); for (size_t index = 0; index < exception_codes.size(); ++index) { expect_exception.ExceptionRecord.ExceptionInformation[index] = exception_codes[index]; diff --git a/minidump/minidump_file_writer.cc b/minidump/minidump_file_writer.cc index d46b61ae..3d321c0b 100644 --- a/minidump/minidump_file_writer.cc +++ b/minidump/minidump_file_writer.cc @@ -194,7 +194,7 @@ std::vector MinidumpFileWriter::Children() { return children; } -bool MinidumpFileWriter::WillWriteAtOffsetImpl(off_t offset) { +bool MinidumpFileWriter::WillWriteAtOffsetImpl(FileOffset offset) { DCHECK_EQ(state(), kStateFrozen); DCHECK_EQ(offset, 0); DCHECK_EQ(streams_.size(), stream_types_.size()); diff --git a/minidump/minidump_file_writer.h b/minidump/minidump_file_writer.h index fed26e1a..8b738b64 100644 --- a/minidump/minidump_file_writer.h +++ b/minidump/minidump_file_writer.h @@ -27,6 +27,7 @@ #include "minidump/minidump_extensions.h" #include "minidump/minidump_stream_writer.h" #include "minidump/minidump_writable.h" +#include "util/file/file_io.h" #include "util/stdlib/pointer_container.h" namespace crashpad { @@ -105,7 +106,7 @@ class MinidumpFileWriter final : public internal::MinidumpWritable { bool Freeze() override; size_t SizeOfObject() override; std::vector Children() override; - bool WillWriteAtOffsetImpl(off_t offset) override; + bool WillWriteAtOffsetImpl(FileOffset offset) override; bool WriteObject(FileWriterInterface* file_writer) override; private: diff --git a/minidump/minidump_memory_writer.cc b/minidump/minidump_memory_writer.cc index a65f5989..606623e4 100644 --- a/minidump/minidump_memory_writer.cc +++ b/minidump/minidump_memory_writer.cc @@ -129,7 +129,7 @@ size_t MinidumpMemoryWriter::SizeOfObject() { return MemoryRangeSize(); } -bool MinidumpMemoryWriter::WillWriteAtOffsetImpl(off_t offset) { +bool MinidumpMemoryWriter::WillWriteAtOffsetImpl(FileOffset offset) { DCHECK_EQ(state(), kStateFrozen); // There will always be at least one registered descriptor, the one for this diff --git a/minidump/minidump_memory_writer.h b/minidump/minidump_memory_writer.h index 0a6a0e65..6b5f2dfe 100644 --- a/minidump/minidump_memory_writer.h +++ b/minidump/minidump_memory_writer.h @@ -26,6 +26,7 @@ #include "base/memory/scoped_ptr.h" #include "minidump/minidump_stream_writer.h" #include "minidump/minidump_writable.h" +#include "util/file/file_io.h" #include "util/stdlib/pointer_container.h" namespace crashpad { @@ -105,7 +106,7 @@ class MinidumpMemoryWriter : public internal::MinidumpWritable { //! \note Valid in #kStateFrozen or any subsequent state. size_t Alignment() override; - bool WillWriteAtOffsetImpl(off_t offset) override; + bool WillWriteAtOffsetImpl(FileOffset offset) override; //! \brief Returns the object’s desired write phase. //! diff --git a/minidump/minidump_module_crashpad_info_writer_test.cc b/minidump/minidump_module_crashpad_info_writer_test.cc index f458b6a6..458913fe 100644 --- a/minidump/minidump_module_crashpad_info_writer_test.cc +++ b/minidump/minidump_module_crashpad_info_writer_test.cc @@ -34,8 +34,9 @@ const MinidumpModuleCrashpadInfoList* MinidumpModuleCrashpadInfoListAtStart( const std::string& file_contents, size_t count) { MINIDUMP_LOCATION_DESCRIPTOR location_descriptor; - location_descriptor.DataSize = sizeof(MinidumpModuleCrashpadInfoList) + - count * sizeof(MinidumpModuleCrashpadInfoLink); + location_descriptor.DataSize = + static_cast(sizeof(MinidumpModuleCrashpadInfoList) + + count * sizeof(MinidumpModuleCrashpadInfoLink)); location_descriptor.Rva = 0; const MinidumpModuleCrashpadInfoList* list = diff --git a/minidump/minidump_module_writer.cc b/minidump/minidump_module_writer.cc index f932422c..dc5eddfa 100644 --- a/minidump/minidump_module_writer.cc +++ b/minidump/minidump_module_writer.cc @@ -19,6 +19,7 @@ #include #include "base/logging.h" +#include "base/numerics/safe_conversions.h" #include "minidump/minidump_string_writer.h" #include "minidump/minidump_writer_util.h" #include "snapshot/module_snapshot.h" @@ -154,13 +155,14 @@ bool MinidumpModuleMiscDebugRecordWriter::Freeze() { // NUL-terminate. if (!image_debug_misc_.Unicode) { DCHECK(data_utf16_.empty()); - image_debug_misc_.Length = offsetof(decltype(image_debug_misc_), Data) + - (data_.size() + 1) * sizeof(data_[0]); + image_debug_misc_.Length = base::checked_cast( + offsetof(decltype(image_debug_misc_), Data) + + (data_.size() + 1) * sizeof(data_[0])); } else { DCHECK(data_.empty()); - image_debug_misc_.Length = + image_debug_misc_.Length = base::checked_cast( offsetof(decltype(image_debug_misc_), Data) + - (data_utf16_.size() + 1) * sizeof(data_utf16_[0]); + (data_utf16_.size() + 1) * sizeof(data_utf16_[0])); } return true; diff --git a/minidump/minidump_simple_string_dictionary_writer_test.cc b/minidump/minidump_simple_string_dictionary_writer_test.cc index f1f6814f..0f9a71bd 100644 --- a/minidump/minidump_simple_string_dictionary_writer_test.cc +++ b/minidump/minidump_simple_string_dictionary_writer_test.cc @@ -31,9 +31,9 @@ const MinidumpSimpleStringDictionary* MinidumpSimpleStringDictionaryAtStart( const std::string& file_contents, size_t count) { MINIDUMP_LOCATION_DESCRIPTOR location_descriptor; - location_descriptor.DataSize = + location_descriptor.DataSize = static_cast( sizeof(MinidumpSimpleStringDictionary) + - count * sizeof(MinidumpSimpleStringDictionaryEntry); + count * sizeof(MinidumpSimpleStringDictionaryEntry)); location_descriptor.Rva = 0; return MinidumpWritableAtLocationDescriptor( file_contents, location_descriptor); diff --git a/minidump/minidump_thread_id_map.cc b/minidump/minidump_thread_id_map.cc index a6ac6fdd..1fab698e 100644 --- a/minidump/minidump_thread_id_map.cc +++ b/minidump/minidump_thread_id_map.cc @@ -19,6 +19,7 @@ #include #include "base/logging.h" +#include "base/numerics/safe_conversions.h" #include "snapshot/thread_snapshot.h" namespace crashpad { @@ -54,7 +55,8 @@ void BuildMinidumpThreadIDMap( for (const ThreadSnapshot* thread_snapshot : thread_snapshots) { uint64_t thread_id_64 = thread_snapshot->ThreadID(); if (thread_id_map->find(thread_id_64) == thread_id_map->end()) { - uint32_t thread_id_32 = thread_id_map->size(); + uint32_t thread_id_32 = + base::checked_cast(thread_id_map->size()); thread_id_map->insert(std::make_pair(thread_id_64, thread_id_32)); } } diff --git a/minidump/minidump_writable.cc b/minidump/minidump_writable.cc index 5925a885..8b739060 100644 --- a/minidump/minidump_writable.cc +++ b/minidump/minidump_writable.cc @@ -43,7 +43,7 @@ bool MinidumpWritable::WriteEverything(FileWriterInterface* file_writer) { DCHECK_EQ(state_, kStateFrozen); - off_t offset = 0; + FileOffset offset = 0; std::vector write_sequence; size_t size = WillWriteAtOffset(kPhaseEarly, &offset, &write_sequence); if (size == kInvalidSize) { @@ -124,9 +124,9 @@ MinidumpWritable::Phase MinidumpWritable::WritePhase() { size_t MinidumpWritable::WillWriteAtOffset( Phase phase, - off_t* offset, + FileOffset* offset, std::vector* write_sequence) { - off_t local_offset = *offset; + FileOffset local_offset = *offset; CHECK_GE(local_offset, 0); size_t leading_pad_bytes_this_phase; @@ -218,10 +218,10 @@ size_t MinidumpWritable::WillWriteAtOffset( std::vector children = Children(); for (MinidumpWritable* child : children) { // Use “auto” here because it’s impossible to know whether size_t (size) or - // off_t (local_offset) is the wider type, and thus what type the result of - // adding these two variables will have. + // FileOffset (local_offset) is the wider type, and thus what type the + // result of adding these two variables will have. auto unaligned_child_offset = local_offset + size; - off_t child_offset; + FileOffset child_offset; if (!AssignIfInRange(&child_offset, unaligned_child_offset)) { LOG(ERROR) << "offset " << unaligned_child_offset << " out of range"; return kInvalidSize; @@ -239,7 +239,7 @@ size_t MinidumpWritable::WillWriteAtOffset( return leading_pad_bytes_this_phase + size; } -bool MinidumpWritable::WillWriteAtOffsetImpl(off_t offset) { +bool MinidumpWritable::WillWriteAtOffsetImpl(FileOffset offset) { return true; } diff --git a/minidump/minidump_writable.h b/minidump/minidump_writable.h index 3a6cb05c..9e7cf71d 100644 --- a/minidump/minidump_writable.h +++ b/minidump/minidump_writable.h @@ -22,6 +22,7 @@ #include #include "base/basictypes.h" +#include "util/file/file_io.h" namespace crashpad { @@ -212,7 +213,7 @@ class MinidumpWritable { //! processing when an object transitions to #kStateWritable should //! implement WillWriteAtOffsetImpl(), which is called by this method. size_t WillWriteAtOffset(Phase phase, - off_t* offset, + FileOffset* offset, std::vector* write_sequence); //! \brief Called once an object’s writable file offset is determined, as it @@ -232,7 +233,7 @@ class MinidumpWritable { //! //! \note Valid in #kStateFrozen. The object will transition to //! #kStateWritable after this method returns. - virtual bool WillWriteAtOffsetImpl(off_t offset); + virtual bool WillWriteAtOffsetImpl(FileOffset offset); //! \brief Writes the object, transitioning it from #kStateWritable to //! #kStateWritten. diff --git a/minidump/minidump_writable_test.cc b/minidump/minidump_writable_test.cc index 184ac71e..38d97de3 100644 --- a/minidump/minidump_writable_test.cc +++ b/minidump/minidump_writable_test.cc @@ -89,7 +89,7 @@ class BaseTestMinidumpWritable : public crashpad::internal::MinidumpWritable { return has_phase_ ? phase_ : MinidumpWritable::Phase(); } - bool WillWriteAtOffsetImpl(off_t offset) override { + bool WillWriteAtOffsetImpl(FileOffset offset) override { EXPECT_EQ(state(), kStateFrozen); expected_offset_ = offset; bool rv = MinidumpWritable::WillWriteAtOffsetImpl(offset); @@ -107,7 +107,7 @@ class BaseTestMinidumpWritable : public crashpad::internal::MinidumpWritable { private: std::vector children_; - off_t expected_offset_; + FileOffset expected_offset_; size_t alignment_; Phase phase_; bool has_alignment_; diff --git a/minidump/test/minidump_memory_writer_test_util.cc b/minidump/test/minidump_memory_writer_test_util.cc index 472a1a32..4944e6df 100644 --- a/minidump/test/minidump_memory_writer_test_util.cc +++ b/minidump/test/minidump_memory_writer_test_util.cc @@ -42,7 +42,7 @@ size_t TestMinidumpMemoryWriter::MemoryRangeSize() const { return size_; } -bool TestMinidumpMemoryWriter::WillWriteAtOffsetImpl(off_t offset) { +bool TestMinidumpMemoryWriter::WillWriteAtOffsetImpl(FileOffset offset) { EXPECT_EQ(state(), kStateFrozen); expected_offset_ = offset; bool rv = MinidumpMemoryWriter::WillWriteAtOffsetImpl(offset); diff --git a/minidump/test/minidump_memory_writer_test_util.h b/minidump/test/minidump_memory_writer_test_util.h index 391b467a..f4b97675 100644 --- a/minidump/test/minidump_memory_writer_test_util.h +++ b/minidump/test/minidump_memory_writer_test_util.h @@ -44,12 +44,12 @@ class TestMinidumpMemoryWriter final : public MinidumpMemoryWriter { size_t MemoryRangeSize() const override; // MinidumpWritable: - bool WillWriteAtOffsetImpl(off_t offset) override; + bool WillWriteAtOffsetImpl(FileOffset offset) override; bool WriteObject(FileWriterInterface* file_writer) override; private: uint64_t base_address_; - off_t expected_offset_; + FileOffset expected_offset_; size_t size_; uint8_t value_; diff --git a/minidump/test/minidump_rva_list_test_util.cc b/minidump/test/minidump_rva_list_test_util.cc index 48de0bff..ebaa8f07 100644 --- a/minidump/test/minidump_rva_list_test_util.cc +++ b/minidump/test/minidump_rva_list_test_util.cc @@ -26,7 +26,8 @@ namespace test { const MinidumpRVAList* MinidumpRVAListAtStart(const std::string& file_contents, size_t count) { MINIDUMP_LOCATION_DESCRIPTOR location_descriptor; - location_descriptor.DataSize = sizeof(MinidumpRVAList) + count * sizeof(RVA); + location_descriptor.DataSize = + static_cast(sizeof(MinidumpRVAList) + count * sizeof(RVA)); location_descriptor.Rva = 0; const MinidumpRVAList* list = diff --git a/snapshot/minidump/process_snapshot_minidump_test.cc b/snapshot/minidump/process_snapshot_minidump_test.cc index a214309e..12cdd790 100644 --- a/snapshot/minidump/process_snapshot_minidump_test.cc +++ b/snapshot/minidump/process_snapshot_minidump_test.cc @@ -63,7 +63,7 @@ TEST(ProcessSnapshotMinidump, Empty) { RVA WriteString(FileWriterInterface* writer, const std::string& string) { RVA rva = static_cast(writer->SeekGet()); - uint32_t string_size = string.size(); + uint32_t string_size = static_cast(string.size()); EXPECT_TRUE(writer->Write(&string_size, sizeof(string_size))); // Include the trailing NUL character. @@ -88,16 +88,17 @@ void WriteMinidumpSimpleStringDictionary( location->Rva = static_cast(writer->SeekGet()); - const uint32_t simple_string_dictionary_entries = entries.size(); + const uint32_t simple_string_dictionary_entries = + static_cast(entries.size()); EXPECT_TRUE(writer->Write(&simple_string_dictionary_entries, sizeof(simple_string_dictionary_entries))); for (const MinidumpSimpleStringDictionaryEntry& entry : entries) { EXPECT_TRUE(writer->Write(&entry, sizeof(entry))); } - location->DataSize = + location->DataSize = static_cast( sizeof(simple_string_dictionary_entries) + - entries.size() * sizeof(MinidumpSimpleStringDictionaryEntry); + entries.size() * sizeof(MinidumpSimpleStringDictionaryEntry)); } // Writes |strings| to |writer| as a MinidumpRVAList referencing @@ -113,13 +114,14 @@ void WriteMinidumpStringList(MINIDUMP_LOCATION_DESCRIPTOR* location, location->Rva = static_cast(writer->SeekGet()); - const uint32_t string_list_entries = rvas.size(); + const uint32_t string_list_entries = static_cast(rvas.size()); EXPECT_TRUE(writer->Write(&string_list_entries, sizeof(string_list_entries))); for (RVA rva : rvas) { EXPECT_TRUE(writer->Write(&rva, sizeof(rva))); } - location->DataSize = sizeof(string_list_entries) + rvas.size() * sizeof(RVA); + location->DataSize = static_cast(sizeof(string_list_entries) + + rvas.size() * sizeof(RVA)); } TEST(ProcessSnapshotMinidump, AnnotationsSimpleMap) { diff --git a/snapshot/win/process_reader_win.cc b/snapshot/win/process_reader_win.cc index 77fe0e24..383a6646 100644 --- a/snapshot/win/process_reader_win.cc +++ b/snapshot/win/process_reader_win.cc @@ -16,9 +16,7 @@ namespace crashpad { -ProcessReaderWin::ProcessReaderWin() - : initialized_(), - is_64_bit_(false) { +ProcessReaderWin::ProcessReaderWin() : process_info_(), initialized_() { } ProcessReaderWin::~ProcessReaderWin() { @@ -27,6 +25,8 @@ ProcessReaderWin::~ProcessReaderWin() { bool ProcessReaderWin::Initialize(HANDLE process) { INITIALIZATION_STATE_SET_INITIALIZING(initialized_); + process_info_.Initialize(process); + INITIALIZATION_STATE_SET_VALID(initialized_); return true; } diff --git a/snapshot/win/process_reader_win.h b/snapshot/win/process_reader_win.h index 58a06815..1e079f0f 100644 --- a/snapshot/win/process_reader_win.h +++ b/snapshot/win/process_reader_win.h @@ -18,6 +18,7 @@ #include #include "util/misc/initialization_state_dcheck.h" +#include "util/win/process_info.h" namespace crashpad { @@ -39,10 +40,10 @@ class ProcessReaderWin { bool Initialize(HANDLE process); //! \return `true` if the target task is a 64-bit process. - bool Is64Bit() const { return is_64_bit_; } + bool Is64Bit() const { return process_info_.Is64Bit(); } private: - bool is_64_bit_; + ProcessInfo process_info_; InitializationStateDcheck initialized_; DISALLOW_COPY_AND_ASSIGN(ProcessReaderWin); diff --git a/util/net/http_multipart_builder.cc b/util/net/http_multipart_builder.cc index 29b00af0..83186af6 100644 --- a/util/net/http_multipart_builder.cc +++ b/util/net/http_multipart_builder.cc @@ -46,7 +46,8 @@ std::string GenerateBoundaryString() { for (int index = 0; index < 32; ++index) { const char kCharacters[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - int random_value = base::RandInt(0, strlen(kCharacters) - 1); + int random_value = + base::RandInt(0, static_cast(strlen(kCharacters)) - 1); boundary_string += kCharacters[random_value]; } boundary_string += "---"; diff --git a/util/net/http_transport_win.cc b/util/net/http_transport_win.cc index 2fe89deb..2b6e372f 100644 --- a/util/net/http_transport_win.cc +++ b/util/net/http_transport_win.cc @@ -18,6 +18,7 @@ #include #include "base/logging.h" +#include "base/numerics/safe_conversions.h" #include "base/scoped_generic.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" @@ -149,10 +150,11 @@ bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) { for (const auto& pair : headers()) { std::wstring header_string = base::UTF8ToUTF16(pair.first) + L": " + base::UTF8ToUTF16(pair.second); - if (!WinHttpAddRequestHeaders(request.get(), - header_string.c_str(), - header_string.size(), - WINHTTP_ADDREQ_FLAG_ADD)) { + if (!WinHttpAddRequestHeaders( + request.get(), + header_string.c_str(), + base::checked_cast(header_string.size()), + WINHTTP_ADDREQ_FLAG_ADD)) { LogErrorWinHttpMessage("WinHttpAddRequestHeaders"); return false; } @@ -178,8 +180,8 @@ bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) { WINHTTP_NO_ADDITIONAL_HEADERS, 0, &post_data[0], - post_data.size(), - post_data.size(), + base::checked_cast(post_data.size()), + base::checked_cast(post_data.size()), 0)) { LogErrorWinHttpMessage("WinHttpSendRequest"); return false; diff --git a/util/win/process_info.h b/util/win/process_info.h index 3bfb7d44..2c01668a 100644 --- a/util/win/process_info.h +++ b/util/win/process_info.h @@ -37,8 +37,8 @@ struct FULL_PROCESS_BASIC_INFORMATION { PPEB PebBaseAddress; KAFFINITY AffinityMask; PVOID BasePriority; - ULONG UniqueProcessId; - ULONG InheritedFromUniqueProcessId; + ULONG_PTR UniqueProcessId; + ULONG_PTR InheritedFromUniqueProcessId; }; } // namespace internal