Skip to content

Commit 5bca0f2

Browse files
committed
fixed a crash when accessing an invalid json object
1 parent 1e35043 commit 5bca0f2

File tree

1 file changed

+16
-0
lines changed
  • src/framework/global/serialization

1 file changed

+16
-0
lines changed

src/framework/global/serialization/json.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,22 +602,38 @@ bool JsonObject::isValid() const
602602

603603
bool JsonObject::empty() const
604604
{
605+
if (!isValid()) {
606+
return true;
607+
}
608+
605609
return object_const(m_data).size() == 0;
606610
}
607611

608612
size_t JsonObject::size() const
609613
{
614+
if (!isValid()) {
615+
return 0;
616+
}
617+
610618
return object_const(m_data).size();
611619
}
612620

613621
bool JsonObject::contains(const std::string& key) const
614622
{
623+
if (!isValid()) {
624+
return false;
625+
}
626+
615627
const picojson::object& o = object_const(m_data);
616628
return o.find(key) != o.cend();
617629
}
618630

619631
JsonValue JsonObject::value(const std::string& key, JsonValue def) const
620632
{
633+
if (!isValid()) {
634+
return def;
635+
}
636+
621637
const picojson::object& o = object_const(m_data);
622638
auto it = o.find(key);
623639
if (it != o.cend()) {

0 commit comments

Comments
 (0)