Commit 92a78310 authored by Peter Kasting's avatar Peter Kasting Committed by Chromium LUCI CQ

Prevent segfaults due to bad pointer conversion with inheritance.

If we pass a View* through a void*, we need to cast to View* on the
other side before any casting to a View subclass, or the pointer will
not be fixed up correctly.

In this case, we can just pass as a View* directly, avoiding the void*,
and the cast-to-derived Just Works.

Found this while trying to add metadata to OmniboxViewViews, which
inherits from views::Textfield but does not have that as the first base
class.

Bug: none
Change-Id: I5abc3efc3abbbe470ab23b3579984767f9e51b1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2625752
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Wei Li <weili@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarWei Li <weili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842873}
parent a7532bfa
......@@ -137,7 +137,7 @@ void ClassMetaData::SetTypeName(const std::string& type_name) {
type_name_ = type_name;
}
void MemberMetaDataBase::SetValueAsString(void* obj,
void MemberMetaDataBase::SetValueAsString(View* obj,
const base::string16& new_value) {
NOTREACHED();
}
......
......@@ -14,6 +14,9 @@
#include "ui/views/views_export.h"
namespace views {
class View;
namespace metadata {
enum class PropertyFlags : uint32_t {
......@@ -151,12 +154,12 @@ class VIEWS_EXPORT MemberMetaDataBase {
// Access the value of this member and return it as a string.
// |obj| is the instance on which to obtain the value of the property this
// metadata represents.
virtual base::string16 GetValueAsString(void* obj) const = 0;
virtual base::string16 GetValueAsString(View* obj) const = 0;
// Set the value of this member through a string on a specified object.
// |obj| is the instance on which to set the value of the property this
// metadata represents.
virtual void SetValueAsString(void* obj, const base::string16& new_value);
virtual void SetValueAsString(View* obj, const base::string16& new_value);
// Return various information flags about the property.
virtual PropertyFlags GetPropertyFlags() const = 0;
......
......@@ -14,6 +14,7 @@
#include "ui/views/metadata/metadata_cache.h"
#include "ui/views/metadata/metadata_types.h"
#include "ui/views/metadata/type_conversion.h"
#include "ui/views/view.h"
#include "ui/views/views_export.h"
namespace views {
......@@ -32,7 +33,7 @@ class ClassPropertyReadOnlyMetaData : public MemberMetaDataBase {
using MemberMetaDataBase::MemberMetaDataBase;
~ClassPropertyReadOnlyMetaData() override = default;
base::string16 GetValueAsString(void* obj) const override {
base::string16 GetValueAsString(View* obj) const override {
if (!kIsSerializable)
return base::string16();
return TypeConverter<TValue>::ToString((static_cast<TClass*>(obj)->*Get)());
......@@ -69,7 +70,7 @@ class ClassPropertyMetaData
ClassPropertyReadOnlyMetaData;
~ClassPropertyMetaData() override = default;
void SetValueAsString(void* obj, const base::string16& new_value) override {
void SetValueAsString(View* obj, const base::string16& new_value) override {
if (!kIsSerializable)
return;
if (base::Optional<TValue> result =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment