Skip to content

Commit

Permalink
Fixes to make prevent_unsafe_narrowing for ui/views build on trybots.
Browse files Browse the repository at this point in the history
Bug: 1292951
Change-Id: Ic7a9f846535d764ea6292f1b4c535a2988184cb8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3789799
Reviewed-by: Nasko Oskov <nasko@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Mike West <mkwst@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Adam Rice <ricea@chromium.org>
Reviewed-by: Hiroki Sato <hirokisato@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/main@{#1034084}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed Aug 11, 2022
1 parent da433ee commit 7064abb
Show file tree
Hide file tree
Showing 60 changed files with 145 additions and 125 deletions.
2 changes: 1 addition & 1 deletion ash/components/arc/ime/arc_ime_service.cc
Expand Up @@ -548,7 +548,7 @@ bool ArcImeService::CanComposeInline() const {
return true;
}

bool ArcImeService::GetCompositionCharacterBounds(uint32_t index,
bool ArcImeService::GetCompositionCharacterBounds(size_t index,
gfx::Rect* rect) const {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion ash/components/arc/ime/arc_ime_service.h
Expand Up @@ -132,7 +132,7 @@ class ArcImeService : public KeyedService,
base::i18n::TextDirection GetTextDirection() const override;
int GetTextInputFlags() const override;
bool CanComposeInline() const override;
bool GetCompositionCharacterBounds(uint32_t index,
bool GetCompositionCharacterBounds(size_t index,
gfx::Rect* rect) const override;
bool HasCompositionText() const override;
FocusReason GetFocusReason() const override;
Expand Down
2 changes: 1 addition & 1 deletion base/hash/md5_constexpr_internal.h
Expand Up @@ -82,7 +82,7 @@ struct MD5CE {
DCHECK_EQ(m % 64, 0u);
if (i < n) {
// Emit the message itself...
return data[i];
return static_cast<uint8_t>(data[i]);
} else if (i == n) {
// ...followed by the end of message marker.
return 0x80;
Expand Down
8 changes: 3 additions & 5 deletions components/exo/shared_memory.cc
Expand Up @@ -42,7 +42,7 @@ SharedMemory::~SharedMemory() {}
std::unique_ptr<Buffer> SharedMemory::CreateBuffer(const gfx::Size& size,
gfx::BufferFormat format,
unsigned offset,
int stride) {
uint32_t stride) {
TRACE_EVENT2("exo", "SharedMemory::CreateBuffer", "size", size.ToString(),
"format", static_cast<int>(format));

Expand All @@ -52,10 +52,8 @@ std::unique_ptr<Buffer> SharedMemory::CreateBuffer(const gfx::Size& size,
return nullptr;
}

if (!base::IsValueInRangeForNumericType<size_t>(stride) ||
gfx::RowSizeForBufferFormat(size.width(), format, 0) >
static_cast<size_t>(stride) ||
static_cast<size_t>(stride) & 3) {
if (gfx::RowSizeForBufferFormat(size.width(), format, 0) > stride ||
stride & 3) {
DLOG(WARNING) << "Failed to create shm buffer. Unsupported stride "
<< stride;
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion components/exo/shared_memory.h
Expand Up @@ -34,7 +34,7 @@ class SharedMemory {
std::unique_ptr<Buffer> CreateBuffer(const gfx::Size& size,
gfx::BufferFormat format,
unsigned offset,
int stride);
uint32_t stride);

size_t GetSize() const;
bool Resize(const size_t new_size);
Expand Down
2 changes: 1 addition & 1 deletion components/exo/text_input.cc
Expand Up @@ -255,7 +255,7 @@ gfx::Rect TextInput::GetSelectionBoundingBox() const {
return gfx::Rect();
}

bool TextInput::GetCompositionCharacterBounds(uint32_t index,
bool TextInput::GetCompositionCharacterBounds(size_t index,
gfx::Rect* rect) const {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion components/exo/text_input.h
Expand Up @@ -182,7 +182,7 @@ class TextInput : public ui::TextInputClient,
bool CanComposeInline() const override;
gfx::Rect GetCaretBounds() const override;
gfx::Rect GetSelectionBoundingBox() const override;
bool GetCompositionCharacterBounds(uint32_t index,
bool GetCompositionCharacterBounds(size_t index,
gfx::Rect* rect) const override;
bool HasCompositionText() const override;
ui::TextInputClient::FocusReason GetFocusReason() const override;
Expand Down
2 changes: 1 addition & 1 deletion components/viz/test/test_gpu_memory_buffer_manager.cc
Expand Up @@ -75,7 +75,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
handle.type = gfx::SHARED_MEMORY_BUFFER;
handle.region = region_.Duplicate();
handle.offset = base::checked_cast<uint32_t>(offset_);
handle.stride = base::checked_cast<int32_t>(stride_);
handle.stride = base::checked_cast<uint32_t>(stride_);
return handle;
}
void OnMemoryDump(
Expand Down
2 changes: 1 addition & 1 deletion components/viz/test/test_image_factory.cc
Expand Up @@ -26,7 +26,7 @@ scoped_refptr<gl::GLImage> TestImageFactory::CreateImageForGpuMemoryBuffer(
DCHECK_EQ(handle.type, gfx::SHARED_MEMORY_BUFFER);
auto image = base::MakeRefCounted<gl::GLImageSharedMemory>(size);
if (!image->Initialize(handle.region, handle.id, format, handle.offset,
base::checked_cast<size_t>(handle.stride)))
handle.stride))
return nullptr;

return image;
Expand Down
Expand Up @@ -1386,7 +1386,7 @@ gfx::Rect RenderWidgetHostViewAura::GetSelectionBoundingBox() const {
}

bool RenderWidgetHostViewAura::GetCompositionCharacterBounds(
uint32_t index,
size_t index,
gfx::Rect* rect) const {
DCHECK(rect);

Expand Down
Expand Up @@ -223,7 +223,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
bool CanComposeInline() const override;
gfx::Rect GetCaretBounds() const override;
gfx::Rect GetSelectionBoundingBox() const override;
bool GetCompositionCharacterBounds(uint32_t index,
bool GetCompositionCharacterBounds(size_t index,
gfx::Rect* rect) const override;
bool HasCompositionText() const override;
ui::TextInputClient::FocusReason GetFocusReason() const override;
Expand Down
12 changes: 6 additions & 6 deletions content/web_test/renderer/text_input_controller.cc
Expand Up @@ -57,8 +57,8 @@ class TextInputControllerBindings
bool HasMarkedText();
std::vector<int> MarkedRange();
std::vector<int> SelectedRange();
std::vector<int> FirstRectForCharacterRange(unsigned location,
unsigned length);
std::vector<int> FirstRectForCharacterRange(uint32_t location,
uint32_t length);
void SetComposition(const std::string& text);
void SetCompositionWithReplacementRange(const std::string& text,
int replacement_start,
Expand Down Expand Up @@ -186,8 +186,8 @@ std::vector<int> TextInputControllerBindings::SelectedRange() {
}

std::vector<int> TextInputControllerBindings::FirstRectForCharacterRange(
unsigned location,
unsigned length) {
uint32_t location,
uint32_t length) {
return controller_ ? controller_->FirstRectForCharacterRange(location, length)
: std::vector<int>();
}
Expand Down Expand Up @@ -363,8 +363,8 @@ std::vector<int> TextInputController::SelectedRange() {
}

std::vector<int> TextInputController::FirstRectForCharacterRange(
unsigned location,
unsigned length) {
uint32_t location,
uint32_t length) {
gfx::Rect rect;
if (!view()->FocusedFrame() ||
!view()->FocusedFrame()->FirstRectForCharacterRange(location, length,
Expand Down
4 changes: 2 additions & 2 deletions content/web_test/renderer/text_input_controller.h
Expand Up @@ -48,8 +48,8 @@ class TextInputController {
bool HasMarkedText();
std::vector<int> MarkedRange();
std::vector<int> SelectedRange();
std::vector<int> FirstRectForCharacterRange(unsigned location,
unsigned length);
std::vector<int> FirstRectForCharacterRange(uint32_t location,
uint32_t length);
void SetComposition(const std::string& text,
int replacement_range_start,
int replacement_range_end);
Expand Down
Expand Up @@ -224,8 +224,6 @@ scoped_refptr<gl::GLImage> GLImageBackingFactory::MakeGLImage(
if (handle.type == gfx::SHARED_MEMORY_BUFFER) {
if (plane != gfx::BufferPlane::DEFAULT)
return nullptr;
if (!base::IsValueInRangeForNumericType<size_t>(handle.stride))
return nullptr;
auto image = base::MakeRefCounted<gl::GLImageSharedMemory>(size);
if (color_space.IsValid())
image->SetColorSpace(color_space);
Expand Down
Expand Up @@ -767,7 +767,7 @@ TEST_P(GLImageBackingFactoryWithGMBTest, GpuMemoryBufferImportSharedMemory) {
handle.region = base::UnsafeSharedMemoryRegion::Create(shm_size);
ASSERT_TRUE(handle.region.IsValid());
handle.offset = 0;
handle.stride = static_cast<int32_t>(
handle.stride = static_cast<uint32_t>(
gfx::RowSizeForBufferFormat(size.width(), format, 0));

auto backing = backing_factory_shmem_->CreateSharedImage(
Expand Down
4 changes: 2 additions & 2 deletions gpu/command_buffer/service/shared_memory_region_wrapper.cc
Expand Up @@ -17,11 +17,11 @@ namespace {
// Validate that |stride| will work for pixels with |size| and |format|.
bool ValidateStride(const gfx::Size size,
viz::ResourceFormat format,
int32_t stride) {
uint32_t stride) {
if (!base::IsValueInRangeForNumericType<size_t>(stride))
return false;

int32_t min_width_in_bytes = 0;
uint32_t min_width_in_bytes = 0;
if (!viz::ResourceSizes::MaybeWidthInBytes(size.width(), format,
&min_width_in_bytes)) {
return false;
Expand Down
15 changes: 7 additions & 8 deletions gpu/ipc/common/gpu_memory_buffer_impl_shared_memory.cc
Expand Up @@ -30,7 +30,7 @@ GpuMemoryBufferImplSharedMemory::GpuMemoryBufferImplSharedMemory(
base::UnsafeSharedMemoryRegion shared_memory_region,
base::WritableSharedMemoryMapping shared_memory_mapping,
size_t offset,
int stride)
uint32_t stride)
: GpuMemoryBufferImpl(id, size, format, std::move(callback)),
shared_memory_region_(std::move(shared_memory_region)),
shared_memory_mapping_(std::move(shared_memory_mapping)),
Expand Down Expand Up @@ -89,7 +89,7 @@ GpuMemoryBufferImplSharedMemory::CreateGpuMemoryBuffer(
handle.type = gfx::SHARED_MEMORY_BUFFER;
handle.id = id;
handle.offset = 0;
handle.stride = static_cast<int32_t>(
handle.stride = static_cast<uint32_t>(
gfx::RowSizeForBufferFormat(size.width(), format, 0));
handle.region = std::move(shared_memory_region);
return handle;
Expand All @@ -114,19 +114,18 @@ GpuMemoryBufferImplSharedMemory::CreateFromHandle(
size_t min_buffer_size = 0;

if (gfx::NumberOfPlanesForLinearBufferFormat(format) == 1) {
if (static_cast<size_t>(handle.stride) < minimum_stride)
if (handle.stride < minimum_stride)
return nullptr;

base::CheckedNumeric<size_t> checked_min_buffer_size =
base::MakeCheckedNum(handle.stride) *
(base::MakeCheckedNum(size.height()) - 1) +
minimum_stride;
base::CheckedNumeric<size_t> checked_min_buffer_size = handle.stride;
checked_min_buffer_size *= size.height() - 1;
checked_min_buffer_size += minimum_stride;
if (!checked_min_buffer_size.AssignIfValid(&min_buffer_size))
return nullptr;
} else {
// Custom layout (i.e. non-standard stride) is not allowed for multi-plane
// formats.
if (static_cast<size_t>(handle.stride) != minimum_stride)
if (handle.stride != minimum_stride)
return nullptr;

if (!gfx::BufferSizeForBufferFormatChecked(size, format,
Expand Down
4 changes: 2 additions & 2 deletions gpu/ipc/common/gpu_memory_buffer_impl_shared_memory.h
Expand Up @@ -85,12 +85,12 @@ class GPU_EXPORT GpuMemoryBufferImplSharedMemory : public GpuMemoryBufferImpl {
base::UnsafeSharedMemoryRegion shared_memory_region,
base::WritableSharedMemoryMapping shared_memory_mapping,
size_t offset,
int stride);
uint32_t stride);

base::UnsafeSharedMemoryRegion shared_memory_region_;
base::WritableSharedMemoryMapping shared_memory_mapping_;
size_t offset_;
int stride_;
uint32_t stride_;
};

} // namespace gpu
Expand Down
2 changes: 0 additions & 2 deletions gpu/ipc/service/gpu_channel.cc
Expand Up @@ -1066,8 +1066,6 @@ scoped_refptr<gl::GLImage> GpuChannel::CreateImageForGpuMemoryBuffer(
case gfx::SHARED_MEMORY_BUFFER: {
if (plane != gfx::BufferPlane::DEFAULT)
return nullptr;
if (!base::IsValueInRangeForNumericType<size_t>(handle.stride))
return nullptr;
auto image = base::MakeRefCounted<gl::GLImageSharedMemory>(size);
if (!image->Initialize(handle.region, handle.id, format, handle.offset,
handle.stride)) {
Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_message.cc
Expand Up @@ -70,7 +70,7 @@ Message::Message(int32_t routing_id, uint32_t type, PriorityValue priority)
Init();
}

Message::Message(const char* data, int data_len)
Message::Message(const char* data, size_t data_len)
: base::Pickle(data, data_len) {
Init();
}
Expand Down
4 changes: 2 additions & 2 deletions ipc/ipc_message.h
Expand Up @@ -66,7 +66,7 @@ class IPC_MESSAGE_SUPPORT_EXPORT Message : public base::Pickle {
// Initializes a message from a const block of data. The data is not copied;
// instead the data is merely referenced by this message. Only const methods
// should be used on the message when initialized this way.
Message(const char* data, int data_len);
Message(const char* data, size_t data_len);

Message(const Message& other);
Message& operator=(const Message& other);
Expand Down Expand Up @@ -111,7 +111,7 @@ class IPC_MESSAGE_SUPPORT_EXPORT Message : public base::Pickle {
if (unblock) {
header()->flags |= UNBLOCK_BIT;
} else {
header()->flags &= ~UNBLOCK_BIT;
header()->flags &= static_cast<uint32_t>(~UNBLOCK_BIT);
}
}

Expand Down
8 changes: 6 additions & 2 deletions ipc/ipc_message_utils.h
Expand Up @@ -191,7 +191,9 @@ struct ParamTraits<int> {
template <>
struct ParamTraits<unsigned int> {
typedef unsigned int param_type;
static void Write(base::Pickle* m, const param_type& p) { m->WriteInt(p); }
static void Write(base::Pickle* m, const param_type& p) {
m->WriteInt(static_cast<int>(p));
}
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
param_type* r) {
Expand Down Expand Up @@ -260,7 +262,9 @@ struct ParamTraits<long long> {
template <>
struct ParamTraits<unsigned long long> {
typedef unsigned long long param_type;
static void Write(base::Pickle* m, const param_type& p) { m->WriteInt64(p); }
static void Write(base::Pickle* m, const param_type& p) {
m->WriteInt64(static_cast<int64_t>(p));
}
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
param_type* r) {
Expand Down
3 changes: 2 additions & 1 deletion net/http/http_version.h
Expand Up @@ -16,7 +16,8 @@ class HttpVersion {
HttpVersion() : value_(0) { }

// Build from unsigned major/minor pair.
HttpVersion(uint16_t major, uint16_t minor) : value_(major << 16 | minor) {}
HttpVersion(uint16_t major, uint16_t minor)
: value_(static_cast<uint32_t>(major << 16) | minor) {}

// Major version number.
uint16_t major_value() const { return value_ >> 16; }
Expand Down
5 changes: 3 additions & 2 deletions net/traffic_annotation/network_traffic_annotation.h
Expand Up @@ -21,8 +21,9 @@ namespace {
// Recursively compute hash code of the given string as a constant expression.
template <int N>
constexpr uint32_t recursive_hash(const char* str) {
return static_cast<uint32_t>((recursive_hash<N - 1>(str) * 31 + str[N - 1]) %
138003713);
return (recursive_hash<N - 1>(str) * 31u +
static_cast<uint32_t>(str[N - 1])) %
138003713u;
}

// Recursion stopper for the above function. Note that string of size 0 will
Expand Down
4 changes: 2 additions & 2 deletions services/network/public/cpp/network_param_mojom_traits.h
Expand Up @@ -52,10 +52,10 @@ template <>
class COMPONENT_EXPORT(NETWORK_CPP_NETWORK_PARAM)
StructTraits<network::mojom::HttpVersionDataView, net::HttpVersion> {
public:
static int16_t major_value(net::HttpVersion version) {
static uint16_t major_value(net::HttpVersion version) {
return version.major_value();
}
static int16_t minor_value(net::HttpVersion version) {
static uint16_t minor_value(net::HttpVersion version) {
return version.minor_value();
}

Expand Down
4 changes: 2 additions & 2 deletions third_party/blink/public/web/web_local_frame.h
Expand Up @@ -475,8 +475,8 @@ class WebLocalFrame : public WebFrame {
virtual WebRange MarkedRange() const = 0;

// Returns the text range rectangle in the viepwort coordinate space.
virtual bool FirstRectForCharacterRange(unsigned location,
unsigned length,
virtual bool FirstRectForCharacterRange(uint32_t location,
uint32_t length,
gfx::Rect&) const = 0;

// Supports commands like Undo, Redo, Cut, Copy, Paste, SelectAll,
Expand Down
7 changes: 4 additions & 3 deletions third_party/blink/renderer/core/editing/ime/edit_context.cc
Expand Up @@ -140,9 +140,10 @@ void EditContext::DispatchTextFormatEvent(
static_cast<WTF::wtf_size_t>(ime_text_spans.size()));

for (const auto& ime_text_span : ime_text_spans) {
const int range_start =
ime_text_span.start_offset + composition_range_start_;
const int range_end = ime_text_span.end_offset + composition_range_start_;
const auto range_start = base::checked_cast<wtf_size_t>(
ime_text_span.start_offset + composition_range_start_);
const auto range_end = base::checked_cast<wtf_size_t>(
ime_text_span.end_offset + composition_range_start_);

String underline_thickness;
String underline_style;
Expand Down

0 comments on commit 7064abb

Please sign in to comment.