浏览代码

LibCpp: Fix null dereference in IfStatement::declarations()

Itamar 4 年之前
父节点
当前提交
68f420ed42
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6 3
      Userland/Libraries/LibCpp/AST.cpp

+ 6 - 3
Userland/Libraries/LibCpp/AST.cpp

@@ -408,9 +408,12 @@ void IfStatement::dump(size_t indent) const
 NonnullRefPtrVector<Declaration> IfStatement::declarations() const
 NonnullRefPtrVector<Declaration> IfStatement::declarations() const
 {
 {
     NonnullRefPtrVector<Declaration> declarations;
     NonnullRefPtrVector<Declaration> declarations;
-    declarations.append(m_predicate->declarations());
-    declarations.append(m_then->declarations());
-    declarations.append(m_else->declarations());
+    if (m_predicate)
+        declarations.append(m_predicate->declarations());
+    if (m_then)
+        declarations.append(m_then->declarations());
+    if (m_else)
+        declarations.append(m_else->declarations());
     return declarations;
     return declarations;
 }
 }