浏览代码

LibGUI: Fix silly nullptr dereference in MessageBox::show()

Since we take the parent object as a raw pointer, we should handle the
case where it's null.
Andreas Kling 5 年之前
父节点
当前提交
3252a6925e
共有 1 个文件被更改,包括 3 次插入1 次删除
  1. 3 1
      Libraries/LibGUI/MessageBox.cpp

+ 3 - 1
Libraries/LibGUI/MessageBox.cpp

@@ -35,7 +35,9 @@ namespace GUI {
 
 int MessageBox::show(const StringView& text, const StringView& title, Type type, InputType input_type, Core::Object* parent)
 {
-    auto box = parent->add<MessageBox>(text, title, type, input_type);
+    auto box = MessageBox::construct(text, title, type, input_type);
+    if (parent)
+        parent->add_child(box);
     return box->exec();
 }