mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
GVariant: Don't crash when extracting a null String.
This commit is contained in:
parent
054c982181
commit
8f4c59c276
Notes:
sideshowbarker
2024-07-19 14:44:25 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/8f4c59c2763
3 changed files with 39 additions and 3 deletions
|
@ -39,6 +39,11 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
String(const StringImpl* impl)
|
||||
: m_impl(const_cast<StringImpl*>(impl))
|
||||
{
|
||||
}
|
||||
|
||||
String(RetainPtr<StringImpl>&& impl)
|
||||
: m_impl(move(impl))
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue