Skip to content

Widget::get_parent() dereferences nullptr for the root Screen #24

Closed

Description

@Aintdev

Where: Source/Widgets/ctui_widget.cpp:17-20, Source/Widgets/ctui_widget.h:24,32-36

const Widget& Widget::get_parent() const { return *_parent; }

_parent is set to nullptr in the Widget() constructor and never overwritten for the Screen singleton (it's the root, has no parent). Calling get_parent() on screen (or any orphaned widget) dereferences a null pointer through a reference — UB.

Suggested fix: either guard/assert for the root case, or change the return type to something that can represent "no parent" (Widget*/std::optional<std::reference_wrapper<Widget>>).

Suggested branch: fix/widget-get-parent-root
Suggested PR title: fix(widget): guard get_parent() against null root parent

Activity

  1. self-assigned this
    on Sep 14, 2026
  2. Aintdev commented on Sep 14, 2026

    @Aintdev
    OwnerAuthor

    plan is to let get_parent() return pointer instead of reference to make it more safe without removing the method from screen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions