GVariant: Don't crash when extracting a null String.

This commit is contained in:
Andreas Kling 2019-04-12 14:43:44 +02:00
parent 054c982181
commit 8f4c59c276
Notes: sideshowbarker 2024-07-19 14:44:25 +09:00
3 changed files with 39 additions and 3 deletions

View file

@ -39,6 +39,11 @@ public:
{
}
String(const StringImpl* impl)
: m_impl(const_cast<StringImpl*>(impl))
{
}
String(RetainPtr<StringImpl>&& impl)
: m_impl(move(impl))
{

View file

@ -6,6 +6,11 @@ GVariant::GVariant()
}
GVariant::~GVariant()
{
clear();
}
void GVariant::clear()
{
switch (m_type) {
case Type::String:
@ -20,6 +25,8 @@ GVariant::~GVariant()
default:
break;
}
m_type = Type::Invalid;
m_value.as_string = nullptr;
}
GVariant::GVariant(int value)
@ -85,9 +92,24 @@ GVariant::GVariant(const Rect& rect)
m_value.as_rect = (const RawRect&)rect;
}
GVariant::GVariant(const GVariant& other)
: m_type(other.m_type)
GVariant& GVariant::operator=(const GVariant& other)
{
if (&other == this)
return *this;
clear();
copy_from(other);
return *this;
}
GVariant::GVariant(const GVariant& other)
{
copy_from(other);
}
void GVariant::copy_from(const GVariant& other)
{
ASSERT(!is_valid());
m_type = other.m_type;
switch (m_type) {
case Type::Bool:
m_value.as_bool = other.m_value.as_bool;
@ -214,6 +236,7 @@ String GVariant::to_string() const
case Type::Rect:
return as_rect().to_string();
case Type::Invalid:
return "[Null]";
break;
}
ASSERT_NOT_REACHED();

View file

@ -19,6 +19,12 @@ public:
GVariant(Color);
GVariant(const GVariant&);
GVariant& operator=(const GVariant&);
GVariant(GVariant&&) = delete;
GVariant& operator=(GVariant&&) = delete;
void clear();
~GVariant();
enum class Type {
@ -84,7 +90,7 @@ public:
String as_string() const
{
ASSERT(type() == Type::String);
return *m_value.as_string;
return m_value.as_string;
}
const GraphicsBitmap& as_bitmap() const
@ -118,6 +124,8 @@ public:
bool operator<(const GVariant&) const;
private:
void copy_from(const GVariant&);
struct RawPoint {
int x;
int y;