fix(companion): nullptr-init screen pointers so a forgotten new() fails safe

Adding a screen touches 4 sites; 3 (member decl, gotoX decl, gotoX def) are
compile-checked, but a missed `new XScreen()` in begin() left the pointer
uninitialised and crashed at first navigation. Give every screen member an
in-class nullptr initialiser and bail early in setCurrScreen(nullptr) so the
mistake is an inert no-op instead of a null deref. Document the 4-site
registration contract on the member block.

A full registry table was considered and rejected: the named gotoXScreen()
methods are a depended-upon API (~30 call sites, menu dispatch + back-nav),
so a table would add an enum + indirection without removing them.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
MarekZegare4
2026-06-29 18:42:59 +02:00
parent eedd47d1e1
commit 15716d2b03
2 changed files with 28 additions and 18 deletions

View File

@@ -1748,8 +1748,13 @@ void UITask::userLedHandler() {
}
void UITask::setCurrScreen(UIScreen* c) {
// Fail safe on a null target: a screen pointer left uninitialised (member
// declared + navigator wired, but the `new XScreen()` line forgotten in
// begin()) stays nullptr thanks to the in-class initialisers. Bail here so
// that mistake is an inert no-op instead of a null deref in render()/poll().
if (!c) return;
curr = c;
if (c) c->onShow(); // central per-visit reset hook (see UIScreen::onShow)
c->onShow(); // central per-visit reset hook (see UIScreen::onShow)
_next_refresh = 100;
}