diff options
author | jam <jam@chromium.org> | 2016-02-10 15:45:40 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-10 23:47:16 +0000 |
commit | ffaec53850a27fc0888998c98c7bb092ccbd8552 (patch) | |
tree | 665d5d9564497e52b6343f33eb9e6ef2636203d0 | |
parent | ac440714860679857517ac7dd4c6282acbfa4033 (diff) | |
download | chromium_src-ffaec53850a27fc0888998c98c7bb092ccbd8552.zip chromium_src-ffaec53850a27fc0888998c98c7bb092ccbd8552.tar.gz chromium_src-ffaec53850a27fc0888998c98c7bb092ccbd8552.tar.bz2 |
Add comments for struct members that were changed from size_t to uin32_t or uint64_t for IPC safety.
Also add a few checked_cast for places where we converted from size_t and we're sure that it's safe.
BUG=581409
Review URL: https://codereview.chromium.org/1684793003
Cr-Commit-Position: refs/heads/master@{#374788}
-rw-r--r-- | chrome/browser/task_management/sampling/task_group.cc | 2 | ||||
-rw-r--r-- | chrome/browser/task_manager/task_manager.cc | 5 | ||||
-rw-r--r-- | chrome/common/spellcheck_marker.h | 3 | ||||
-rw-r--r-- | components/autofill/core/common/form_field_data.h | 3 | ||||
-rw-r--r-- | content/common/gpu/gpu_memory_manager.cc | 2 | ||||
-rw-r--r-- | content/common/gpu/gpu_memory_uma_stats.h | 6 | ||||
-rw-r--r-- | content/public/common/gpu_memory_stats.h | 8 | ||||
-rw-r--r-- | extensions/common/stack_frame.h | 3 | ||||
-rw-r--r-- | media/cast/logging/logging_defines.h | 2 | ||||
-rw-r--r-- | media/cast/net/pacing/paced_sender.cc | 3 | ||||
-rw-r--r-- | media/cast/receiver/frame_receiver.cc | 3 | ||||
-rw-r--r-- | media/cast/sender/frame_sender.cc | 3 | ||||
-rw-r--r-- | ui/gfx/range/range.h | 3 |
13 files changed, 35 insertions, 11 deletions
diff --git a/chrome/browser/task_management/sampling/task_group.cc b/chrome/browser/task_management/sampling/task_group.cc index c8d9bf1..9911136 100644 --- a/chrome/browser/task_management/sampling/task_group.cc +++ b/chrome/browser/task_management/sampling/task_group.cc @@ -188,7 +188,7 @@ void TaskGroup::RefreshGpuMemory( return; } - gpu_memory_ = static_cast<int64_t>(itr->second.video_memory); + gpu_memory_ = itr->second.video_memory; gpu_memory_has_duplicates_ = itr->second.has_duplicates; } diff --git a/chrome/browser/task_manager/task_manager.cc b/chrome/browser/task_manager/task_manager.cc index 0ae5fb3..7d87aa7 100644 --- a/chrome/browser/task_manager/task_manager.cc +++ b/chrome/browser/task_manager/task_manager.cc @@ -8,6 +8,7 @@ #include "base/i18n/number_formatting.h" #include "base/i18n/rtl.h" #include "base/location.h" +#include "base/numerics/safe_conversions.h" #include "base/process/process_metrics.h" #include "base/single_thread_task_runner.h" #include "base/stl_util.h" @@ -666,7 +667,9 @@ bool TaskManagerModel::GetVideoMemory(int index, if (i == video_memory_usage_stats_.process_map.end()) return false; values.is_video_memory_valid = true; - values.video_memory = i->second.video_memory; + // If this checked_cast asserts, then need to change this code to use + // uint64_t instead of size_t. + values.video_memory = base::checked_cast<size_t>(i->second.video_memory); values.video_memory_has_duplicates = i->second.has_duplicates; } *video_memory = values.video_memory; diff --git a/chrome/common/spellcheck_marker.h b/chrome/common/spellcheck_marker.h index 4305c22..ac278536 100644 --- a/chrome/common/spellcheck_marker.h +++ b/chrome/common/spellcheck_marker.h @@ -29,6 +29,9 @@ class SpellCheckMarker { : hash(hash), offset(offset) {} uint32_t hash; + // Note: we use uint32_t instead of size_t because this struct is sent over + // IPC which could span 32 & 64 bit processes. This is fine since the offset + // shouldn't exceed UINT32_MAX even on 64 bit builds. uint32_t offset; }; diff --git a/components/autofill/core/common/form_field_data.h b/components/autofill/core/common/form_field_data.h index 0317239..a3e923d 100644 --- a/components/autofill/core/common/form_field_data.h +++ b/components/autofill/core/common/form_field_data.h @@ -45,6 +45,9 @@ struct FormFieldData { base::string16 value; std::string form_control_type; std::string autocomplete_attribute; + // Note: we use uint32_t instead of size_t because this struct is sent over + // IPC which could span 32 & 64 bit processes. This is fine since the length + // shouldn't exceed UINT32_MAX even on 64 bit builds. uint32_t max_length; bool is_autofilled; bool is_checked; diff --git a/content/common/gpu/gpu_memory_manager.cc b/content/common/gpu/gpu_memory_manager.cc index 4b9eb7c..10f769c 100644 --- a/content/common/gpu/gpu_memory_manager.cc +++ b/content/common/gpu/gpu_memory_manager.cc @@ -118,7 +118,7 @@ void GpuMemoryManager::SendUmaStatsToBrowser() { GPUMemoryUmaStats params; params.bytes_allocated_current = GetCurrentUsage(); params.bytes_allocated_max = bytes_allocated_historical_max_; - params.context_group_count = tracking_groups_.size(); + params.context_group_count = static_cast<uint32_t>(tracking_groups_.size()); channel_manager_->Send(new GpuHostMsg_GpuMemoryUmaStats(params)); } } // namespace content diff --git a/content/common/gpu/gpu_memory_uma_stats.h b/content/common/gpu/gpu_memory_uma_stats.h index 16c8813..daf91bf 100644 --- a/content/common/gpu/gpu_memory_uma_stats.h +++ b/content/common/gpu/gpu_memory_uma_stats.h @@ -11,6 +11,8 @@ namespace content { // Memory usage statistics send periodically to the browser process to report // in UMA histograms if the GPU process crashes. +// Note: we use uint64_t instead of size_t for byte count because this struct +// is sent over IPC which could span 32 & 64 bit processes. struct GPUMemoryUmaStats { GPUMemoryUmaStats() : bytes_allocated_current(0), @@ -19,10 +21,10 @@ struct GPUMemoryUmaStats { } // The number of bytes currently allocated. - uint32_t bytes_allocated_current; + uint64_t bytes_allocated_current; // The maximum number of bytes ever allocated at once. - uint32_t bytes_allocated_max; + uint64_t bytes_allocated_max; // The number of context groups. uint32_t context_group_count; diff --git a/content/public/common/gpu_memory_stats.h b/content/public/common/gpu_memory_stats.h index 09bda3f..ed358ab 100644 --- a/content/public/common/gpu_memory_stats.h +++ b/content/public/common/gpu_memory_stats.h @@ -17,6 +17,8 @@ namespace content { +// Note: we use uint64_t instead of size_t for byte count because this struct +// is sent over IPC which could span 32 & 64 bit processes. struct CONTENT_EXPORT GPUVideoMemoryUsageStats { GPUVideoMemoryUsageStats(); ~GPUVideoMemoryUsageStats(); @@ -26,7 +28,7 @@ struct CONTENT_EXPORT GPUVideoMemoryUsageStats { ~ProcessStats(); // The bytes of GPU resources accessible by this process - uint32_t video_memory; + uint64_t video_memory; // Set to true if this process' GPU resource count is inflated because // it is counting other processes' resources (e.g, the GPU process has @@ -39,10 +41,10 @@ struct CONTENT_EXPORT GPUVideoMemoryUsageStats { ProcessMap process_map; // The total amount of GPU memory allocated at the time of the request. - uint32_t bytes_allocated; + uint64_t bytes_allocated; // The maximum amount of GPU memory ever allocated at once. - uint32_t bytes_allocated_historical_max; + uint64_t bytes_allocated_historical_max; }; } // namespace content diff --git a/extensions/common/stack_frame.h b/extensions/common/stack_frame.h index b174ffc..a55b8d8 100644 --- a/extensions/common/stack_frame.h +++ b/extensions/common/stack_frame.h @@ -29,6 +29,9 @@ struct StackFrame { bool operator==(const StackFrame& rhs) const; + // Note: we use uint32_t instead of size_t because this struct is sent over + // IPC which could span 32 & 64 bit processes. This is fine since line numbers + // and column numbers shouldn't exceed UINT32_MAX even on 64 bit builds. uint32_t line_number; uint32_t column_number; base::string16 source; diff --git a/media/cast/logging/logging_defines.h b/media/cast/logging/logging_defines.h index 7d17507..00425be 100644 --- a/media/cast/logging/logging_defines.h +++ b/media/cast/logging/logging_defines.h @@ -64,6 +64,8 @@ struct FrameEvent { int height; // Size of encoded frame in bytes. Only set for FRAME_ENCODED event. + // Note: we use uint32_t instead of size_t for byte count because this struct + // is sent over IPC which could span 32 & 64 bit processes. uint32_t size; // Time of event logged. diff --git a/media/cast/net/pacing/paced_sender.cc b/media/cast/net/pacing/paced_sender.cc index 1084901..6de3956 100644 --- a/media/cast/net/pacing/paced_sender.cc +++ b/media/cast/net/pacing/paced_sender.cc @@ -8,6 +8,7 @@ #include "base/bind.h" #include "base/debug/dump_without_crashing.h" #include "base/message_loop/message_loop.h" +#include "base/numerics/safe_conversions.h" namespace media { namespace cast { @@ -354,7 +355,7 @@ void PacedSender::LogPacketEvent(const Packet& packet, CastLoggingEvent type) { success &= reader.Skip(2); success &= reader.ReadU16(&event.packet_id); success &= reader.ReadU16(&event.max_packet_id); - event.size = packet.size(); + event.size = base::checked_cast<uint32_t>(packet.size()); DCHECK(success); } diff --git a/media/cast/receiver/frame_receiver.cc b/media/cast/receiver/frame_receiver.cc index aa8efb7..7236135 100644 --- a/media/cast/receiver/frame_receiver.cc +++ b/media/cast/receiver/frame_receiver.cc @@ -11,6 +11,7 @@ #include "base/bind.h" #include "base/logging.h" #include "base/message_loop/message_loop.h" +#include "base/numerics/safe_conversions.h" #include "media/cast/cast_config.h" #include "media/cast/cast_defines.h" #include "media/cast/cast_environment.h" @@ -129,7 +130,7 @@ void FrameReceiver::ProcessParsedPacket(const RtpCastHeader& rtp_header, receive_event->frame_id = rtp_header.frame_id; receive_event->packet_id = rtp_header.packet_id; receive_event->max_packet_id = rtp_header.max_packet_id; - receive_event->size = payload_size; + receive_event->size = base::checked_cast<uint32_t>(payload_size); cast_environment_->logger()->DispatchPacketEvent(std::move(receive_event)); bool duplicate = false; diff --git a/media/cast/sender/frame_sender.cc b/media/cast/sender/frame_sender.cc index 535f2eb..8ddfdb7 100644 --- a/media/cast/sender/frame_sender.cc +++ b/media/cast/sender/frame_sender.cc @@ -10,6 +10,7 @@ #include <vector> #include "base/macros.h" +#include "base/numerics/safe_conversions.h" #include "base/trace_event/trace_event.h" #include "media/cast/cast_defines.h" #include "media/cast/constants.h" @@ -239,7 +240,7 @@ void FrameSender::SendEncodedFrame( encode_event->media_type = is_audio_ ? AUDIO_EVENT : VIDEO_EVENT; encode_event->rtp_timestamp = encoded_frame->rtp_timestamp; encode_event->frame_id = frame_id; - encode_event->size = encoded_frame->data.size(); + encode_event->size = base::checked_cast<uint32_t>(encoded_frame->data.size()); encode_event->key_frame = encoded_frame->dependency == EncodedFrame::KEY; encode_event->target_bitrate = requested_bitrate_before_encode; encode_event->encoder_cpu_utilization = encoded_frame->deadline_utilization; diff --git a/ui/gfx/range/range.h b/ui/gfx/range/range.h index c99ca22..3d9c724 100644 --- a/ui/gfx/range/range.h +++ b/ui/gfx/range/range.h @@ -108,6 +108,9 @@ class GFX_EXPORT Range { std::string ToString() const; private: + // Note: we use uint32_t instead of size_t because this struct is sent over + // IPC which could span 32 & 64 bit processes. This is fine since text spans + // shouldn't exceed UINT32_MAX even on 64 bit builds. uint32_t start_; uint32_t end_; }; |