diff options
author | pkasting <pkasting@chromium.org> | 2014-10-13 13:58:39 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-13 20:59:18 +0000 |
commit | 7bc277b97e9f5f3b470c4b6ccd9337ff73892159 (patch) | |
tree | b6d16809dd1f5965a2bb38d50bab27a22f1e998a | |
parent | 21860bb80f4b5710d633dfd89bf25bc7beaec0c6 (diff) | |
download | chromium_src-7bc277b97e9f5f3b470c4b6ccd9337ff73892159.zip chromium_src-7bc277b97e9f5f3b470c4b6ccd9337ff73892159.tar.gz chromium_src-7bc277b97e9f5f3b470c4b6ccd9337ff73892159.tar.bz2 |
Misc. cleanup, primarily removing unused locals.
Also various other fixes, e.g. condensing code, converting DCHECK_LT(0, a) -> DCHECK_GT(a, 0) (and the like) for readability, inserting a few typecasts.
BUG=none
TEST=none
Review URL: https://codereview.chromium.org/637023002
Cr-Commit-Position: refs/heads/master@{#299362}
24 files changed, 106 insertions, 134 deletions
diff --git a/chrome/app/chrome_crash_reporter_client.cc b/chrome/app/chrome_crash_reporter_client.cc index ff19cb9d..c5f2657 100644 --- a/chrome/app/chrome_crash_reporter_client.cc +++ b/chrome/app/chrome_crash_reporter_client.cc @@ -216,12 +216,11 @@ void ChromeCrashReporterClient::InitBrowserCrashDumpsRegKey() { // browser process might have the same process id and tick count, but crash // before consuming the signal (overwriting the signal with an identical one). // For now, we're willing to live with that risk. - int length = base::strings::SafeSPrintf(g_browser_crash_dump_prefix, - kBrowserCrashDumpPrefixTemplate, - chrome::kChromeVersion, - ::GetCurrentProcessId(), - ::GetTickCount()); - if (length <= 0) { + if (base::strings::SafeSPrintf(g_browser_crash_dump_prefix, + kBrowserCrashDumpPrefixTemplate, + chrome::kChromeVersion, + ::GetCurrentProcessId(), + ::GetTickCount()) <= 0) { NOTREACHED(); g_browser_crash_dump_prefix[0] = '\0'; return; @@ -241,13 +240,10 @@ void ChromeCrashReporterClient::RecordCrashDumpAttempt(bool is_real_crash) { // base value name). const size_t kMaxValueSize = 2 * kBrowserCrashDumpPrefixLength; char value_name[kMaxValueSize + 1] = {}; - int length = base::strings::SafeSPrintf( - value_name, - "%s-%x", - g_browser_crash_dump_prefix, - base::subtle::NoBarrier_AtomicIncrement(&g_browser_crash_dump_count, 1)); - - if (length > 0) { + if (base::strings::SafeSPrintf( + value_name, "%s-%x", g_browser_crash_dump_prefix, + base::subtle::NoBarrier_AtomicIncrement(&g_browser_crash_dump_count, + 1)) > 0) { DWORD value_dword = is_real_crash ? 1 : 0; ::RegSetValueExA(g_browser_crash_dump_regkey, value_name, 0, REG_DWORD, reinterpret_cast<BYTE*>(&value_dword), diff --git a/chrome/browser/ui/webui/devtools_ui.cc b/chrome/browser/ui/webui/devtools_ui.cc index 94945c1..85db059 100644 --- a/chrome/browser/ui/webui/devtools_ui.cc +++ b/chrome/browser/ui/webui/devtools_ui.cc @@ -234,9 +234,10 @@ void DevToolsDataSource::StartBundledDataRequest( int resource_id = content::DevToolsHttpHandler::GetFrontendResourceId(filename); - DLOG_IF(WARNING, -1 == resource_id) << "Unable to find dev tool resource: " - << filename << ". If you compiled with debug_devtools=1, try running" - " with --debug-devtools."; + DLOG_IF(WARNING, resource_id == -1) + << "Unable to find dev tool resource: " << filename + << ". If you compiled with debug_devtools=1, try running with " + "--debug-devtools."; const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); scoped_refptr<base::RefCountedStaticMemory> bytes(rb.LoadDataResourceBytes( resource_id)); diff --git a/chrome/installer/util/installer_state.cc b/chrome/installer/util/installer_state.cc index 6ec0734..37c711a 100644 --- a/chrome/installer/util/installer_state.cc +++ b/chrome/installer/util/installer_state.cc @@ -630,7 +630,6 @@ bool InstallerState::AnyExistsAndIsInUse( // Check only for the current version (i.e., the version we are upgrading // _from_). Later versions from pending in-use updates need not be checked // since the current version is guaranteed to be in use if any such are. - bool in_use = false; scoped_ptr<Version> current_version(GetCurrentVersion(machine_state)); if (!current_version) return false; diff --git a/chrome/service/service_utility_process_host.cc b/chrome/service/service_utility_process_host.cc index f08a3bd..86a7d394 100644 --- a/chrome/service/service_utility_process_host.cc +++ b/chrome/service/service_utility_process_host.cc @@ -232,7 +232,6 @@ bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) { bool ServiceUtilityProcessHost::Launch(base::CommandLine* cmd_line, bool no_sandbox) { if (no_sandbox) { - base::ProcessHandle process = base::kNullProcessHandle; cmd_line->AppendSwitch(switches::kNoSandbox); base::LaunchProcess(*cmd_line, base::LaunchOptions(), &handle_); } else { diff --git a/components/crash/app/breakpad_win.cc b/components/crash/app/breakpad_win.cc index 5fe19c4..32c4891 100644 --- a/components/crash/app/breakpad_win.cc +++ b/components/crash/app/breakpad_win.cc @@ -375,6 +375,7 @@ extern "C" int __declspec(dllexport) CrashForException( return EXCEPTION_CONTINUE_SEARCH; } +#ifndef _WIN64 static NTSTATUS WINAPI HookNtTerminateProcess(HANDLE ProcessHandle, NTSTATUS ExitStatus) { if (g_breakpad && @@ -440,6 +441,7 @@ static void InitTerminateProcessHooks() { old_protect, &old_protect)); } +#endif static void InitPipeNameEnvVar(bool is_per_user_install) { scoped_ptr<base::Environment> env(base::Environment::Create()); diff --git a/components/crash/tools/crash_service.cc b/components/crash/tools/crash_service.cc index 48dcbc8..7e1798f 100644 --- a/components/crash/tools/crash_service.cc +++ b/components/crash/tools/crash_service.cc @@ -92,7 +92,7 @@ bool CreateTopWindow(HINSTANCE instance, bool visible) { wcx.lpfnWndProc = CrashSvcWndProc; wcx.hInstance = instance; wcx.lpszClassName = L"crash_svc_class"; - ATOM atom = ::RegisterClassExW(&wcx); + ::RegisterClassExW(&wcx); DWORD style = visible ? WS_POPUPWINDOW | WS_VISIBLE : WS_OVERLAPPED; // The window size is zero but being a popup window still shows in the @@ -466,7 +466,6 @@ PSECURITY_DESCRIPTOR CrashService::GetSecurityDescriptorForLowIntegrity() { // Build the SDDL string for the label. std::wstring sddl = L"S:(ML;;NW;;;S-1-16-4096)"; - DWORD error = ERROR_SUCCESS; PSECURITY_DESCRIPTOR sec_desc = NULL; PACL sacl = NULL; diff --git a/components/wifi/wifi_service_win.cc b/components/wifi/wifi_service_win.cc index fe2d308..972406b 100644 --- a/components/wifi/wifi_service_win.cc +++ b/components/wifi/wifi_service_win.cc @@ -1708,7 +1708,6 @@ DWORD WiFiServiceImpl::SetProfile(bool shared, } bool WiFiServiceImpl::HaveProfile(const std::string& network_guid) { - DWORD error = ERROR_SUCCESS; std::string profile_xml; return GetProfile(network_guid, false, &profile_xml) == ERROR_SUCCESS; } diff --git a/content/browser/devtools/devtools_http_handler_impl.cc b/content/browser/devtools/devtools_http_handler_impl.cc index 9029441..90ee8d2 100644 --- a/content/browser/devtools/devtools_http_handler_impl.cc +++ b/content/browser/devtools/devtools_http_handler_impl.cc @@ -431,7 +431,7 @@ void DevToolsHttpHandlerImpl::OnHttpRequest( int resource_id = DevToolsHttpHandler::GetFrontendResourceId(filename); if (resource_id != -1) { base::StringPiece data = GetContentClient()->GetDataResource( - resource_id, ui::SCALE_FACTOR_NONE); + resource_id, ui::SCALE_FACTOR_NONE); server_->Send200(connection_id, data.as_string(), mime_type); return; } diff --git a/content/browser/fileapi/obfuscated_file_util_unittest.cc b/content/browser/fileapi/obfuscated_file_util_unittest.cc index b4b6bfb..eb97846 100644 --- a/content/browser/fileapi/obfuscated_file_util_unittest.cc +++ b/content/browser/fileapi/obfuscated_file_util_unittest.cc @@ -2187,7 +2187,6 @@ TEST_F(ObfuscatedFileUtilTest, TestQuotaOnMoveFile) { from_file, from_file_size)); ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); - int64 to_file_size ALLOW_UNUSED = from_file_size; from_file_size = 0; ASSERT_EQ(base::File::FILE_OK, ofu()->CopyOrMoveFile( diff --git a/content/test/plugin/plugin_get_javascript_url_test.cc b/content/test/plugin/plugin_get_javascript_url_test.cc index a2f6985..b2ac515 100644 --- a/content/test/plugin/plugin_get_javascript_url_test.cc +++ b/content/test/plugin/plugin_get_javascript_url_test.cc @@ -89,7 +89,7 @@ void CALLBACK ExecuteGetJavascriptUrlTest::TimerProc( NPVariant result_var; this_instance->npn_evaluate_context_ = true; - NPError result = this_instance->HostFunctions()->evaluate( + this_instance->HostFunctions()->evaluate( this_instance->id(), window_obj, &script_string, &result_var); this_instance->npn_evaluate_context_ = false; } diff --git a/content/test/plugin/plugin_npobject_lifetime_test.cc b/content/test/plugin/plugin_npobject_lifetime_test.cc index 7ef5d26..3e28874 100644 --- a/content/test/plugin/plugin_npobject_lifetime_test.cc +++ b/content/test/plugin/plugin_npobject_lifetime_test.cc @@ -71,8 +71,8 @@ void NPObjectLifetimeTest::URLNotify(const char* url, NPReason reason, // Declare a local variant value. NPVariant variantValue; // Get the location property from the window object (which is another object). - bool b1 = HostFunctions()->getproperty(id(), other_plugin_instance_object_, - identifier, &variantValue ); + HostFunctions()->getproperty(id(), other_plugin_instance_object_, identifier, + &variantValue ); HostFunctions()->releaseobject(other_plugin_instance_object_); other_plugin_instance_object_ = NULL; // If this test failed, then we'd have crashed by now. @@ -165,7 +165,7 @@ void CALLBACK NPObjectDeletePluginInNPN_Evaluate::TimerProc( static_cast<unsigned int>(script.length()); NPVariant result_var; - bool result = g_npn_evaluate_test_instance_->HostFunctions()->evaluate( + g_npn_evaluate_test_instance_->HostFunctions()->evaluate( g_npn_evaluate_test_instance_->id(), window_obj, &script_string, &result_var); // If this test failed we would have crashed by now. diff --git a/ipc/ipc_channel_reader.cc b/ipc/ipc_channel_reader.cc index 28a889a..f41a0d7 100644 --- a/ipc/ipc_channel_reader.cc +++ b/ipc/ipc_channel_reader.cc @@ -80,9 +80,8 @@ bool ChannelReader::DispatchInputData(const char* input_data, return false; #ifdef IPC_MESSAGE_LOG_ENABLED - Logging* logger = Logging::GetInstance(); std::string name; - logger->GetMessageText(m.type(), &name, &m, NULL); + Logging::GetInstance()->GetMessageText(m.type(), &name, &m, NULL); TRACE_EVENT1("ipc,toplevel", "ChannelReader::DispatchInputData", "name", name); #else diff --git a/ipc/ipc_sync_channel.cc b/ipc/ipc_sync_channel.cc index 50ea3df..a6ef27a 100644 --- a/ipc/ipc_sync_channel.cc +++ b/ipc/ipc_sync_channel.cc @@ -461,9 +461,8 @@ void SyncChannel::SetRestrictDispatchChannelGroup(int group) { bool SyncChannel::Send(Message* message) { #ifdef IPC_MESSAGE_LOG_ENABLED - Logging* logger = Logging::GetInstance(); std::string name; - logger->GetMessageText(message->type(), &name, message, NULL); + Logging::GetInstance()->GetMessageText(message->type(), &name, message, NULL); TRACE_EVENT1("ipc", "SyncChannel::Send", "name", name); #else TRACE_EVENT2("ipc", "SyncChannel::Send", diff --git a/net/base/escape.cc b/net/base/escape.cc index ab70f1d..7ce21a1 100644 --- a/net/base/escape.cc +++ b/net/base/escape.cc @@ -114,7 +114,7 @@ bool UnescapeUnsignedCharAtIndex(const STR& escaped_text, static_cast<typename STR::value_type>(escaped_text[index + 2])); if (IsHexDigit(most_sig_digit) && IsHexDigit(least_sig_digit)) { *value = HexDigitToInt(most_sig_digit) * 16 + - HexDigitToInt(least_sig_digit); + HexDigitToInt(least_sig_digit); return true; } return false; diff --git a/net/disk_cache/cache_util.cc b/net/disk_cache/cache_util.cc index ea39df0..1671138 100644 --- a/net/disk_cache/cache_util.cc +++ b/net/disk_cache/cache_util.cc @@ -145,15 +145,12 @@ int PreferredCacheSize(int64 available) { if (available < 0) return kDefaultCacheSize; - int64 max_size = PreferredCacheSizeInternal(available); - // Limit cache size to somewhat less than kint32max to avoid potential // integer overflows in cache backend implementations. - DCHECK(kDefaultCacheSize * 4 < kint32max); - if (max_size > kDefaultCacheSize * 4) - max_size = kDefaultCacheSize * 4; - - return implicit_cast<int32>(max_size); + DCHECK_LT(kDefaultCacheSize * 4, kint32max); + return static_cast<int32>(std::min( + PreferredCacheSizeInternal(available), + static_cast<int64>(kDefaultCacheSize * 4))); } } // namespace disk_cache diff --git a/net/disk_cache/simple/simple_synchronous_entry.cc b/net/disk_cache/simple/simple_synchronous_entry.cc index 1e7b9aa..c50c9a3 100644 --- a/net/disk_cache/simple/simple_synchronous_entry.cc +++ b/net/disk_cache/simple/simple_synchronous_entry.cc @@ -14,6 +14,7 @@ #include "base/files/file_util.h" #include "base/hash.h" #include "base/location.h" +#include "base/numerics/safe_conversions.h" #include "base/sha1.h" #include "base/strings/stringprintf.h" #include "net/base/io_buffer.h" @@ -73,7 +74,7 @@ enum CloseResult { void RecordSyncOpenResult(net::CacheType cache_type, OpenEntryResult result, bool had_index) { - DCHECK_GT(OPEN_ENTRY_MAX, result); + DCHECK_LT(result, OPEN_ENTRY_MAX); SIMPLE_CACHE_UMA(ENUMERATION, "SyncOpenResult", cache_type, result, OPEN_ENTRY_MAX); if (had_index) { @@ -104,8 +105,8 @@ void RecordCloseResult(net::CacheType cache_type, CloseResult result) { } bool CanOmitEmptyFile(int file_index) { - DCHECK_LE(0, file_index); - DCHECK_GT(disk_cache::kSimpleEntryFileCount, file_index); + DCHECK_GE(file_index, 0); + DCHECK_LT(file_index, disk_cache::kSimpleEntryFileCount); return file_index == disk_cache::simple_util::GetFileIndexFromStreamIndex(2); } @@ -284,7 +285,7 @@ void SimpleSynchronousEntry::ReadData(const EntryOperationData& in_entry_op, int file_index = GetFileIndexFromStreamIndex(in_entry_op.index); // Zero-length reads and reads to the empty streams of omitted files should // be handled in the SimpleEntryImpl. - DCHECK_LT(0, in_entry_op.buf_len); + DCHECK_GT(in_entry_op.buf_len, 0); DCHECK(!empty_file_omitted_[file_index]); File* file = const_cast<File*>(&files_[file_index]); int bytes_read = @@ -408,19 +409,17 @@ void SimpleSynchronousEntry::ReadSparseData( SparseRange* found_range = &it->second; DCHECK_EQ(it->first, found_range->offset); if (found_range->offset + found_range->length > offset) { - DCHECK_LE(0, found_range->length); - DCHECK_GE(kint32max, found_range->length); - DCHECK_LE(0, offset - found_range->offset); - DCHECK_GE(kint32max, offset - found_range->offset); - int range_len_after_offset = found_range->length - - (offset - found_range->offset); - DCHECK_LE(0, range_len_after_offset); + DCHECK_GE(found_range->length, 0); + DCHECK_LE(found_range->length, kint32max); + DCHECK_GE(offset - found_range->offset, 0); + DCHECK_LE(offset - found_range->offset, kint32max); + int net_offset = static_cast<int>(offset - found_range->offset); + int range_len_after_offset = + static_cast<int>(found_range->length - net_offset); + DCHECK_GE(range_len_after_offset, 0); int len_to_read = std::min(buf_len, range_len_after_offset); - if (!ReadSparseRange(found_range, - offset - found_range->offset, - len_to_read, - buf)) { + if (!ReadSparseRange(found_range, net_offset, len_to_read, buf)) { *out_result = net::ERR_CACHE_READ_FAILURE; return; } @@ -436,8 +435,7 @@ void SimpleSynchronousEntry::ReadSparseData( it->second.offset == offset + read_so_far) { SparseRange* found_range = &it->second; DCHECK_EQ(it->first, found_range->offset); - int range_len = (found_range->length > kint32max) ? - kint32max : found_range->length; + int range_len = base::saturated_cast<int>(found_range->length); int len_to_read = std::min(buf_len - read_so_far, range_len); if (!ReadSparseRange(found_range, 0, len_to_read, buf + read_so_far)) { *out_result = net::ERR_CACHE_READ_FAILURE; @@ -484,19 +482,17 @@ void SimpleSynchronousEntry::WriteSparseData( --it; SparseRange* found_range = &it->second; if (found_range->offset + found_range->length > offset) { - DCHECK_LE(0, found_range->length); - DCHECK_GE(kint32max, found_range->length); - DCHECK_LE(0, offset - found_range->offset); - DCHECK_GE(kint32max, offset - found_range->offset); - int range_len_after_offset = found_range->length - - (offset - found_range->offset); - DCHECK_LE(0, range_len_after_offset); + DCHECK_GE(found_range->length, 0); + DCHECK_LE(found_range->length, kint32max); + DCHECK_GE(offset - found_range->offset, 0); + DCHECK_LE(offset - found_range->offset, kint32max); + int net_offset = static_cast<int>(offset - found_range->offset); + int range_len_after_offset = + static_cast<int>(found_range->length - net_offset); + DCHECK_GE(range_len_after_offset, 0); int len_to_write = std::min(buf_len, range_len_after_offset); - if (!WriteSparseRange(found_range, - offset - found_range->offset, - len_to_write, - buf)) { + if (!WriteSparseRange(found_range, net_offset, len_to_write, buf)) { *out_result = net::ERR_CACHE_WRITE_FAILURE; return; } @@ -510,7 +506,8 @@ void SimpleSynchronousEntry::WriteSparseData( it->second.offset < offset + buf_len) { SparseRange* found_range = &it->second; if (offset + written_so_far < found_range->offset) { - int len_to_append = found_range->offset - (offset + written_so_far); + int len_to_append = + static_cast<int>(found_range->offset - (offset + written_so_far)); if (!AppendSparseRange(offset + written_so_far, len_to_append, buf + written_so_far)) { @@ -520,8 +517,7 @@ void SimpleSynchronousEntry::WriteSparseData( written_so_far += len_to_append; appended_so_far += len_to_append; } - int range_len = (found_range->length > kint32max) ? - kint32max : found_range->length; + int range_len = base::saturated_cast<int>(found_range->length); int len_to_write = std::min(buf_len - written_so_far, range_len); if (!WriteSparseRange(found_range, 0, @@ -567,7 +563,7 @@ void SimpleSynchronousEntry::GetAvailableRange( SparseRangeIterator it = sparse_ranges_.lower_bound(offset); int64 start = offset; - int avail_so_far = 0; + int64 avail_so_far = 0; if (it != sparse_ranges_.end() && it->second.offset < offset + len) start = it->second.offset; @@ -589,9 +585,9 @@ void SimpleSynchronousEntry::GetAvailableRange( ++it; } - int len_from_start = len - (start - offset); + int64 len_from_start = len - (start - offset); *out_start = start; - *out_result = std::min(avail_so_far, len_from_start); + *out_result = static_cast<int>(std::min(avail_so_far, len_from_start)); } void SimpleSynchronousEntry::CheckEOFRecord(int index, @@ -680,7 +676,8 @@ void SimpleSynchronousEntry::Close( const int64 cluster_loss = file_size % 4096 ? 4096 - file_size % 4096 : 0; SIMPLE_CACHE_UMA(PERCENTAGE, "LastClusterLossPercent", cache_type_, - cluster_loss * 100 / (cluster_loss + file_size)); + static_cast<base::HistogramBase::Sample>( + cluster_loss * 100 / (cluster_loss + file_size))); } if (sparse_file_open()) @@ -825,7 +822,7 @@ bool SimpleSynchronousEntry::OpenFiles( // 0, stream 1 and one EOF record. The exact distribution of sizes between // stream 1 and stream 0 is only determined after reading the EOF record // for stream 0 in ReadAndValidateStream0. - out_entry_stat->set_data_size(i + 1, file_info.size); + out_entry_stat->set_data_size(i + 1, static_cast<int>(file_info.size)); } SIMPLE_CACHE_UMA(CUSTOM_COUNTS, "SyncOpenEntryAge", cache_type_, @@ -1159,7 +1156,7 @@ bool SimpleSynchronousEntry::DeleteFilesForEntryHash( void SimpleSynchronousEntry::RecordSyncCreateResult(CreateEntryResult result, bool had_index) { - DCHECK_GT(CREATE_ENTRY_MAX, result); + DCHECK_LT(result, CREATE_ENTRY_MAX); SIMPLE_CACHE_UMA(ENUMERATION, "SyncCreateResult", cache_type_, result, CREATE_ENTRY_MAX); if (had_index) { @@ -1256,7 +1253,7 @@ bool SimpleSynchronousEntry::InitializeSparseFile() { bool SimpleSynchronousEntry::ScanSparseFile(int32* out_sparse_data_size) { DCHECK(sparse_file_open()); - int32 sparse_data_size = 0; + int64 sparse_data_size = 0; SimpleFileHeader header; int header_read_result = @@ -1307,11 +1304,11 @@ bool SimpleSynchronousEntry::ScanSparseFile(int32* out_sparse_data_size) { range_header_offset += sizeof(range_header) + range.length; - DCHECK_LE(sparse_data_size, sparse_data_size + range.length); + DCHECK_GE(sparse_data_size + range.length, sparse_data_size); sparse_data_size += range.length; } - *out_sparse_data_size = sparse_data_size; + *out_sparse_data_size = static_cast<int32>(sparse_data_size); sparse_tail_offset_ = range_header_offset; return true; @@ -1321,8 +1318,8 @@ bool SimpleSynchronousEntry::ReadSparseRange(const SparseRange* range, int offset, int len, char* buf) { DCHECK(range); DCHECK(buf); - DCHECK_GE(range->length, offset); - DCHECK_GE(range->length, offset + len); + DCHECK_LE(offset, range->length); + DCHECK_LE(offset + len, range->length); int bytes_read = sparse_file_.Read(range->file_offset + offset, buf, len); if (bytes_read < len) { @@ -1350,8 +1347,8 @@ bool SimpleSynchronousEntry::WriteSparseRange(SparseRange* range, const char* buf) { DCHECK(range); DCHECK(buf); - DCHECK_GE(range->length, offset); - DCHECK_GE(range->length, offset + len); + DCHECK_LE(offset, range->length); + DCHECK_LE(offset + len, range->length); uint32 new_crc32 = 0; if (offset == 0 && len == range->length) { @@ -1390,8 +1387,8 @@ bool SimpleSynchronousEntry::WriteSparseRange(SparseRange* range, bool SimpleSynchronousEntry::AppendSparseRange(int64 offset, int len, const char* buf) { - DCHECK_LE(0, offset); - DCHECK_LT(0, len); + DCHECK_GE(offset, 0); + DCHECK_GT(len, 0); DCHECK(buf); uint32 data_crc32 = crc32(crc32(0L, Z_NULL, 0), diff --git a/net/disk_cache/simple/simple_util.cc b/net/disk_cache/simple/simple_util.cc index 844b695..55f309e 100644 --- a/net/disk_cache/simple/simple_util.cc +++ b/net/disk_cache/simple/simple_util.cc @@ -9,6 +9,7 @@ #include "base/files/file_util.h" #include "base/format_macros.h" #include "base/logging.h" +#include "base/numerics/safe_conversions.h" #include "base/sha1.h" #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" @@ -97,8 +98,7 @@ std::string GetFilenameFromKeyAndFileIndex(const std::string& key, int32 GetDataSizeFromKeyAndFileSize(const std::string& key, int64 file_size) { int64 data_size = file_size - key.size() - sizeof(SimpleFileHeader) - sizeof(SimpleFileEOF); - DCHECK_GE(implicit_cast<int64>(std::numeric_limits<int32>::max()), data_size); - return data_size; + return base::checked_cast<int32>(data_size); } int64 GetFileSizeFromKeyAndDataSize(const std::string& key, int32 data_size) { diff --git a/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc b/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc index b50b579..8d41d66 100644 --- a/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc +++ b/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc @@ -220,7 +220,6 @@ std::string DhcpProxyScriptAdapterFetcher::GetPacURLFromDhcp( DHCPCAPI_PARAMS_ARRAY send_params = { 0, NULL }; - BYTE option_data[] = { 1, 252 }; DHCPCAPI_PARAMS wpad_params = { 0 }; wpad_params.OptionId = 252; wpad_params.IsVendor = FALSE; // Surprising, but intentional. diff --git a/net/spdy/spdy_frame_builder.cc b/net/spdy/spdy_frame_builder.cc index b491e8b..0b85211 100644 --- a/net/spdy/spdy_frame_builder.cc +++ b/net/spdy/spdy_frame_builder.cc @@ -63,8 +63,8 @@ bool SpdyFrameBuilder::WriteControlFrameHeader(const SpdyFramer& framer, SpdyFrameType type, uint8 flags) { DCHECK_GE(SPDY3, version_); - DCHECK_NE(-1, - SpdyConstants::SerializeFrameType(version_, type)); + DCHECK(SpdyConstants::IsValidFrameType( + version_, SpdyConstants::SerializeFrameType(version_, type))); bool success = true; FlagsAndLength flags_length = CreateFlagsAndLength( flags, capacity_ - framer.GetControlFrameHeaderSize()); @@ -101,10 +101,10 @@ bool SpdyFrameBuilder::BeginNewFrame(const SpdyFramer& framer, SpdyFrameType type, uint8 flags, SpdyStreamId stream_id) { - DCHECK(SpdyConstants::IsValidFrameType(version_, - SpdyConstants::SerializeFrameType(version_, type))); + DCHECK(SpdyConstants::IsValidFrameType( + version_, SpdyConstants::SerializeFrameType(version_, type))); DCHECK_EQ(0u, stream_id & ~kStreamIdMask); - DCHECK_LT(SPDY3, framer.protocol_version()); + DCHECK_GT(framer.protocol_version(), SPDY3); bool success = true; if (length_ > 0) { // Update length field for previous frame. @@ -136,7 +136,7 @@ bool SpdyFrameBuilder::WriteString(const std::string& value) { return false; } - if (!WriteUInt16(static_cast<int>(value.size()))) + if (!WriteUInt16(static_cast<uint16>(value.size()))) return false; return WriteBytes(value.data(), static_cast<uint16>(value.size())); @@ -168,17 +168,17 @@ bool SpdyFrameBuilder::RewriteLength(const SpdyFramer& framer) { bool SpdyFrameBuilder::OverwriteLength(const SpdyFramer& framer, size_t length) { - if (version_ <= SPDY3) { - DCHECK_GE(SpdyConstants::GetFrameMaximumSize(version_) - - framer.GetFrameMinimumSize(), - length); + if (version_ < SPDY4) { + DCHECK_LE(length, + SpdyConstants::GetFrameMaximumSize(version_) - + framer.GetFrameMinimumSize()); } else { - DCHECK_GE(SpdyConstants::GetFrameMaximumSize(version_), length); + DCHECK_LE(length, SpdyConstants::GetFrameMaximumSize(version_)); } bool success = false; const size_t old_length = length_; - if (version_ <= SPDY3) { + if (version_ < SPDY4) { FlagsAndLength flags_length = CreateFlagsAndLength( 0, // We're not writing over the flags value anyway. length); @@ -198,7 +198,7 @@ bool SpdyFrameBuilder::OverwriteLength(const SpdyFramer& framer, bool SpdyFrameBuilder::OverwriteFlags(const SpdyFramer& framer, uint8 flags) { - DCHECK_LT(SPDY3, framer.protocol_version()); + DCHECK_GT(framer.protocol_version(), SPDY3); bool success = false; const size_t old_length = length_; // Flags are the fifth octet in the frame prefix. diff --git a/net/spdy/spdy_framer.cc b/net/spdy/spdy_framer.cc index 374506e..fbe3675 100644 --- a/net/spdy/spdy_framer.cc +++ b/net/spdy/spdy_framer.cc @@ -675,15 +675,15 @@ size_t SpdyFramer::ProcessCommonHeader(const char* data, size_t len) { new SpdyFrameReader(current_frame_buffer_.get(), current_frame_buffer_length_)); - uint16 version = 0; bool is_control_frame = false; uint16 control_frame_type_field = - SpdyConstants::DataFrameType(protocol_version()); + SpdyConstants::DataFrameType(protocol_version()); // ProcessControlFrameHeader() will set current_frame_type_ to the // correct value if this is a valid control frame. current_frame_type_ = DATA; if (protocol_version() <= SPDY3) { + uint16 version = 0; bool successful_read = reader->ReadUInt16(&version); DCHECK(successful_read); is_control_frame = (version & kControlFlagMask) != 0; @@ -700,9 +700,6 @@ size_t SpdyFramer::ProcessCommonHeader(const char* data, size_t len) { << " (expected " << protocol_version() << ")"; set_error(SPDY_UNSUPPORTED_VERSION); return 0; - } else { - // Convert version from wire format to SpdyMajorVersion. - version = SpdyConstants::ParseMajorVersion(version); } // We check control_frame_type_field's validity in // ProcessControlFrameHeader(). @@ -722,7 +719,6 @@ size_t SpdyFramer::ProcessCommonHeader(const char* data, size_t len) { remaining_data_length_ = length_field; current_frame_length_ = remaining_data_length_ + reader->GetBytesConsumed(); } else { - version = protocol_version(); uint32 length_field = 0; bool successful_read = reader->ReadUInt24(&length_field); DCHECK(successful_read); @@ -1173,9 +1169,9 @@ void SpdyFramer::WriteHeaderBlock(SpdyFrameBuilder* frame, const SpdyMajorVersion spdy_version, const SpdyHeaderBlock* headers) { if (spdy_version < SPDY3) { - frame->WriteUInt16(headers->size()); // Number of headers. + frame->WriteUInt16(headers->size()); } else { - frame->WriteUInt32(headers->size()); // Number of headers. + frame->WriteUInt32(headers->size()); } SpdyHeaderBlock::const_iterator it; for (it = headers->begin(); it != headers->end(); ++it) { diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc index f4136bd..914f6fe37 100644 --- a/net/spdy/spdy_session_unittest.cc +++ b/net/spdy/spdy_session_unittest.cc @@ -885,7 +885,7 @@ TEST_P(SpdySessionTest, ClientPing) { session->CheckPingStatus(before_ping_time); EXPECT_EQ(0, session->pings_in_flight()); - EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); + EXPECT_GE(session->next_ping_id(), 1U); EXPECT_FALSE(session->check_ping_status_pending()); EXPECT_GE(session->last_activity_time(), before_ping_time); @@ -1302,7 +1302,7 @@ TEST_P(SpdySessionTest, FailedPing) { // Send a PING frame. session->WritePingFrame(1, false); EXPECT_LT(0, session->pings_in_flight()); - EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); + EXPECT_GE(session->next_ping_id(), 1U); EXPECT_TRUE(session->check_ping_status_pending()); // Assert session is not closed. diff --git a/ui/gfx/gdi_util.cc b/ui/gfx/gdi_util.cc index 3030a53..996d01e 100644 --- a/ui/gfx/gdi_util.cc +++ b/ui/gfx/gdi_util.cc @@ -7,13 +7,11 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" -namespace gfx { - -void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) { - CreateBitmapHeaderWithColorDepth(width, height, 32, hdr); -} +namespace { -void CreateBitmapHeaderWithColorDepth(int width, int height, int color_depth, +void CreateBitmapHeaderWithColorDepth(LONG width, + LONG height, + WORD color_depth, BITMAPINFOHEADER* hdr) { // These values are shared with gfx::PlatformDevice hdr->biSize = sizeof(BITMAPINFOHEADER); @@ -29,6 +27,14 @@ void CreateBitmapHeaderWithColorDepth(int width, int height, int color_depth, hdr->biClrImportant = 0; } +} // namespace + +namespace gfx { + +void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) { + CreateBitmapHeaderWithColorDepth(width, height, 32, hdr); +} + void CreateBitmapV4Header(int width, int height, BITMAPV4HEADER* hdr) { // Because bmp v4 header is just an extension, we just create a v3 header and // copy the bits over to the v4 header. @@ -49,17 +55,7 @@ void CreateBitmapV4Header(int width, int height, BITMAPV4HEADER* hdr) { void CreateMonochromeBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) { - hdr->biSize = sizeof(BITMAPINFOHEADER); - hdr->biWidth = width; - hdr->biHeight = -height; - hdr->biPlanes = 1; - hdr->biBitCount = 1; - hdr->biCompression = BI_RGB; - hdr->biSizeImage = 0; - hdr->biXPelsPerMeter = 1; - hdr->biYPelsPerMeter = 1; - hdr->biClrUsed = 0; - hdr->biClrImportant = 0; + CreateBitmapHeaderWithColorDepth(width, height, 1, hdr); } void SubtractRectanglesFromRegion(HRGN hrgn, diff --git a/ui/gfx/gdi_util.h b/ui/gfx/gdi_util.h index 03ae91b..f1c0f50 100644 --- a/ui/gfx/gdi_util.h +++ b/ui/gfx/gdi_util.h @@ -18,11 +18,6 @@ namespace gfx { GFX_EXPORT void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr); -// Creates a BITMAPINFOHEADER structure given the bitmap's size and -// color depth in bits per pixel. -void CreateBitmapHeaderWithColorDepth(int width, int height, int color_depth, - BITMAPINFOHEADER* hdr); - // Creates a BITMAPV4HEADER structure given the bitmap's size. You probably // only need to use BMP V4 if you need transparency (alpha channel). This // function sets the AlphaMask to 0xff000000. diff --git a/ui/gfx/win/hwnd_util.cc b/ui/gfx/win/hwnd_util.cc index 050aa9b..41eead4 100644 --- a/ui/gfx/win/hwnd_util.cc +++ b/ui/gfx/win/hwnd_util.cc @@ -112,7 +112,7 @@ void* SetWindowUserData(HWND hwnd, void* user_data) { void* GetWindowUserData(HWND hwnd) { DWORD process_id = 0; - DWORD thread_id = GetWindowThreadProcessId(hwnd, &process_id); + GetWindowThreadProcessId(hwnd, &process_id); // A window outside the current process needs to be ignored. if (process_id != ::GetCurrentProcessId()) return NULL; |