Skip to content

Commit f63bff8

Browse files
committed
Fix of SIGSEGV in parse_*_from_json functions
1 parent d110532 commit f63bff8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/ipc.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ inline rect_t parse_rect_from_json(const Json::Value& value) {
5252

5353
static std::shared_ptr<container_t> parse_container_from_json(const Json::Value& o) {
5454
#define i3IPC_TYPE_STR "PARSE CONTAINER FROM JSON"
55+
if (o.isNull())
56+
return std::shared_ptr<container_t>();
5557
std::shared_ptr<container_t> container (new container_t());
5658
IPC_JSON_ASSERT_TYPE_OBJECT(o, "o")
5759

@@ -114,6 +116,8 @@ static std::shared_ptr<container_t> parse_container_from_json(const Json::Value
114116
}
115117

116118
static std::shared_ptr<workspace_t> parse_workspace_from_json(const Json::Value& value) {
119+
if (value.isNull())
120+
return std::shared_ptr<workspace_t>();
117121
Json::Value num = value["num"];
118122
Json::Value name = value["name"];
119123
Json::Value visible = value["visible"];
@@ -122,7 +126,7 @@ static std::shared_ptr<workspace_t> parse_workspace_from_json(const Json::Value
122126
Json::Value rect = value["rect"];
123127
Json::Value output = value["output"];
124128

125-
std::shared_ptr<workspace_t> p;
129+
std::shared_ptr<workspace_t> p (new workspace_t());
126130
p->num = num.asInt();
127131
p->name = name.asString();
128132
p->visible = visible.asBool();
@@ -134,12 +138,14 @@ static std::shared_ptr<workspace_t> parse_workspace_from_json(const Json::Value
134138
}
135139

136140
static std::shared_ptr<output_t> parse_output_from_json(const Json::Value& value) {
141+
if (value.isNull())
142+
return std::shared_ptr<output_t>();
137143
Json::Value name = value["name"];
138144
Json::Value active = value["active"];
139145
Json::Value current_workspace = value["current_workspace"];
140146
Json::Value rect = value["rect"];
141147

142-
std::shared_ptr<output_t> p;
148+
std::shared_ptr<output_t> p (new output_t());
143149
p->name = name.asString();
144150
p->active = active.asBool();
145151
p->current_workspace = (current_workspace.isNull() ? std::string() : current_workspace.asString());

0 commit comments

Comments
 (0)