1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:48:12 +00:00

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
3 changed files with 39 additions and 3 deletions

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();