diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/base/escape.cc | 2 | ||||
-rw-r--r-- | net/disk_cache/cache_util.cc | 11 | ||||
-rw-r--r-- | net/disk_cache/simple/simple_synchronous_entry.cc | 89 | ||||
-rw-r--r-- | net/disk_cache/simple/simple_util.cc | 4 | ||||
-rw-r--r-- | net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc | 1 | ||||
-rw-r--r-- | net/spdy/spdy_frame_builder.cc | 26 | ||||
-rw-r--r-- | net/spdy/spdy_framer.cc | 12 | ||||
-rw-r--r-- | net/spdy/spdy_session_unittest.cc | 4 |
8 files changed, 69 insertions, 80 deletions
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. |