From 09df67311f4621cc7504e2281d90241e7605a278 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 28 Aug 2017 10:26:23 +0300 Subject: [PATCH] Fix MSVC build on 64-bit Mostly int<->size_t implicit conversions. Warning 4366 (The result of the unary '&' operator may be unaligned) appears in minidump.cc:907, but I don't know why. It looks aligned to me. Change-Id: I641942adc324f8f9832b20662083dc83498688a8 Reviewed-on: https://chromium-review.googlesource.com/637390 Reviewed-by: Mike Frysinger --- src/build/common.gypi | 2 +- .../unittests/exception_handler_death_test.cc | 6 +++--- .../windows/unittests/exception_handler_test.cc | 2 +- src/client/windows/unittests/minidump_test.cc | 2 +- src/processor/minidump.cc | 16 ++++++++-------- src/processor/range_map-inl.h | 2 +- .../converter/ms_symbol_server_converter.cc | 4 ++-- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/build/common.gypi b/src/build/common.gypi index b9466a32..29990c65 100644 --- a/src/build/common.gypi +++ b/src/build/common.gypi @@ -894,7 +894,7 @@ ], 'msvs_cygwin_dirs': ['<(DEPTH)/third_party/cygwin'], 'msvs_disabled_warnings': [ - 4100, 4127, 4396, 4503, 4512, 4819, 4995, 4702 + 4091, 4100, 4127, 4366, 4396, 4503, 4512, 4819, 4995, 4702 ], 'msvs_settings': { 'VCCLCompilerTool': { diff --git a/src/client/windows/unittests/exception_handler_death_test.cc b/src/client/windows/unittests/exception_handler_death_test.cc index 30600d41..5ef9e64d 100644 --- a/src/client/windows/unittests/exception_handler_death_test.cc +++ b/src/client/windows/unittests/exception_handler_death_test.cc @@ -82,7 +82,7 @@ void ExceptionHandlerDeathTest::SetUp() { // The test case name is exposed as a c-style string, // convert it to a wchar_t string. int dwRet = MultiByteToWideChar(CP_ACP, 0, test_info->name(), - strlen(test_info->name()), + static_cast(strlen(test_info->name())), test_name_wide, MAX_PATH); if (!dwRet) { @@ -293,8 +293,8 @@ wstring find_minidump_in_directory(const wstring &directory) { wstring filename; do { const wchar_t extension[] = L".dmp"; - const int extension_length = sizeof(extension) / sizeof(extension[0]) - 1; - const int filename_length = wcslen(find_data.cFileName); + const size_t extension_length = sizeof(extension) / sizeof(extension[0]) - 1; + const size_t filename_length = wcslen(find_data.cFileName); if (filename_length > extension_length && wcsncmp(extension, find_data.cFileName + filename_length - extension_length, diff --git a/src/client/windows/unittests/exception_handler_test.cc b/src/client/windows/unittests/exception_handler_test.cc index 0e8ee9ff..a4ce12a8 100644 --- a/src/client/windows/unittests/exception_handler_test.cc +++ b/src/client/windows/unittests/exception_handler_test.cc @@ -120,7 +120,7 @@ void ExceptionHandlerTest::SetUp() { // THe test case name is exposed to use as a c-style string, // But we might be working in UNICODE here on Windows. int dwRet = MultiByteToWideChar(CP_ACP, 0, test_info->name(), - strlen(test_info->name()), + static_cast(strlen(test_info->name())), test_name_wide, MAX_PATH); if (!dwRet) { diff --git a/src/client/windows/unittests/minidump_test.cc b/src/client/windows/unittests/minidump_test.cc index d11fccab..82641125 100644 --- a/src/client/windows/unittests/minidump_test.cc +++ b/src/client/windows/unittests/minidump_test.cc @@ -93,7 +93,7 @@ class MinidumpTest: public testing::Test { STATUS_ACCESS_VIOLATION, // ExceptionCode 0, // ExceptionFlags NULL, // ExceptionRecord; - reinterpret_cast(0xCAFEBABE), // ExceptionAddress; + reinterpret_cast(static_cast(0xCAFEBABE)), // ExceptionAddress; 2, // NumberParameters; { EXCEPTION_WRITE_FAULT, reinterpret_cast(this) } }; diff --git a/src/processor/minidump.cc b/src/processor/minidump.cc index 66b3e017..a9c7d23a 100644 --- a/src/processor/minidump.cc +++ b/src/processor/minidump.cc @@ -380,7 +380,7 @@ string TimeTToUTCString(time_t tt) { #endif char timestr[20]; - int rv = strftime(timestr, 20, "%Y-%m-%d %H:%M:%S", ×truct); + size_t rv = strftime(timestr, 20, "%Y-%m-%d %H:%M:%S", ×truct); if (rv == 0) { return string(); } @@ -2034,10 +2034,10 @@ string MinidumpModule::debug_file() const { // that this method (and all other methods in the Minidump family) // return. - unsigned int bytes = + size_t bytes = module_.misc_record.data_size - MDImageDebugMisc_minsize; if (bytes % 2 == 0) { - unsigned int utf16_words = bytes / 2; + size_t utf16_words = bytes / 2; // UTF16ToUTF8 expects a vector, so create a temporary one // and copy the UTF-16 data into it. @@ -2392,8 +2392,8 @@ const MDImageDebugMisc* MinidumpModule::GetMiscRecord(uint32_t* size) { // There is a potential alignment problem, but shouldn't be a problem // in practice due to the layout of MDImageDebugMisc. uint16_t* data16 = reinterpret_cast(&(misc_record->data)); - unsigned int dataBytes = module_.misc_record.data_size - - MDImageDebugMisc_minsize; + size_t dataBytes = module_.misc_record.data_size - + MDImageDebugMisc_minsize; Swap(data16, dataBytes); } } @@ -4004,7 +4004,7 @@ bool MinidumpMiscInfo::Read(uint32_t expected_size) { return false; } - if (!minidump_->SeekSet(saved_position + padding)) { + if (!minidump_->SeekSet(saved_position + static_cast(padding))) { BPLOG(ERROR) << "MinidumpMiscInfo could not seek past the miscellaneous " << "info structure"; return false; @@ -4538,7 +4538,7 @@ bool MinidumpMemoryInfoList::Read(uint32_t expected_size) { infos_ = infos.release(); } - info_count_ = header_number_of_entries; + info_count_ = static_cast(header_number_of_entries); valid_ = true; return true; @@ -4730,7 +4730,7 @@ bool MinidumpLinuxMapsList::Read(uint32_t expected_size) { // Set instance variables. maps_ = maps.release(); - maps_count_ = maps_->size(); + maps_count_ = static_cast(maps_->size()); valid_ = true; return true; } diff --git a/src/processor/range_map-inl.h b/src/processor/range_map-inl.h index 9fe74c50..f7126098 100644 --- a/src/processor/range_map-inl.h +++ b/src/processor/range_map-inl.h @@ -256,7 +256,7 @@ bool RangeMap::RetrieveRangeAtIndex( template int RangeMap::GetCount() const { - return map_.size(); + return static_cast(map_.size()); } diff --git a/src/tools/windows/converter/ms_symbol_server_converter.cc b/src/tools/windows/converter/ms_symbol_server_converter.cc index dd3f770f..71b77097 100644 --- a/src/tools/windows/converter/ms_symbol_server_converter.cc +++ b/src/tools/windows/converter/ms_symbol_server_converter.cc @@ -73,7 +73,7 @@ bool GUIDOrSignatureIdentifier::InitializeFromString( if (length > 32 && length <= 40) { // GUID if (SSCANF(identifier.c_str(), - "%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X%X", + "%08X%04hX%04hX%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX%X", &guid_.Data1, &guid_.Data2, &guid_.Data3, &guid_.Data4[0], &guid_.Data4[1], &guid_.Data4[2], &guid_.Data4[3], @@ -500,7 +500,7 @@ MSSymbolServerConverter::LocateAndConvertSymbolFile( if (!WindowsStringUtils::safe_mbstowcs(pdb_file, &pdb_file_w)) { fprintf(stderr, "LocateAndConvertSymbolFile: " - "WindowsStringUtils::safe_mbstowcs failed for %s\n", + "WindowsStringUtils::safe_mbstowcs failed for %ws\n", pdb_file_w.c_str()); return LOCATE_FAILURE; }