fix: guard entry reads when a directory is empty - #27
Merged
Conversation
Closes #6. Adopted from upstream LoveRetro#723 by Eric Reinsmidt, taken while upstream is still GPL-3.0 (see LoveRetro#765). top->entries->items[top->selected] was loaded unconditionally in both the input and the render path, so an empty directory read an uninitialised pointer out of the capacity-8 allocation Array_new() never clears. The render path then ran assert(entry) over it, which is an abort in a debug build rather than a latent read. This is the fix #6 asked for: hoist the count check above the load in both paths instead of relying on the downstream total>0 guards. The L1/R1 alpha jump handlers get the same treatment, and the assert goes away. Every remaining read of entries->items[top->selected] in this file is now behind a count or total>0 check. Array_new() still leaves its capacity uninitialised - that is unchanged and now unreachable, not fixed. Upstream wrote this for the empty-root case (no roms, Tools hidden); it covers the ordinary empty Roms/ folder #6 describes by the same route. Co-Authored-By: Eric Reinsmidt <eric@reinsmidt.com>
lepht
force-pushed
the
claude/adopt-upstream-723-empty-list
branch
from
August 12, 2026 04:14
986eeb5 to
aa29957
Compare
lepht
pushed a commit
that referenced
this pull request
Aug 12, 2026
Brings in the three upstream adoptions (#26, #27, #28) now on main. One conflict, in the scroll-text block of nextui.c. Both sides edited adjacent lines for unrelated reasons: - this branch added SCREEN_CONTEXTMENU to the outer screen exclusion list - #27 added a total>0 guard to the inner condition Resolved as the union of both, which is the only correct answer here. Taking ours alone drops total>0 and reopens #6 two lines above the top->entries->items[top->selected] read; taking theirs alone drops the context menu exclusion and renders scroll text over it. Git auto-merged the other five guard sites #27 added. Verified after the merge: no assert(entry) remains, every read of entries->items[top->selected] sits behind a count or total>0 check, nextui.c is syntax-clean against the desktop platform headers, and make test passes.
lepht
pushed a commit
that referenced
this pull request
Aug 12, 2026
Carries the main merge (and with it #26, #27, #28) up the stack. Same single conflict as one level down, in the same two lines of nextui.c: this branch had added SCREEN_SEARCH to the outer screen exclusion list on top of SCREEN_CONTEXTMENU, while #27 added a total>0 guard to the inner condition. Resolved as the union again - all four screen exclusions kept, total>0 kept. Verified after the merge: no assert(entry) remains, every read of entries->items[top->selected] is guarded, nextui.c is syntax-clean against the desktop platform headers, and make test passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6. Adopted from upstream LoveRetro/NextUI#723 by @ericreinsmidt.
What this fixes
top->entries->items[top->selected]was loaded unconditionally in both the input and the render path, so an empty directory read an uninitialised pointer out of the capacity-8 allocationArray_new()never clears. The render path then ranassert(entry)over it — an abort in a debug build, not merely a latent read.This is the fix #6 asked for, in its own words: hoist the
count == 0check above the load in both paths, rather than relying on the downstream guards. Upstream arrived at the same shape independently:The
BTN_L1/BTN_R1alpha-jump handlers get the sametotal>0treatment, and theassertgoes away. The render body is wrapped inif (entry), with an else branch that forceslist_show_entry_namesso an empty folder renders a usable state instead of a black screen.Scope check
After this, every read of
entries->items[top->selected]innextui.csits behind a count ortotal>0check — I audited all of them, not just the two upstream touched. The remaining loop-indexed reads are bounded bycountand were never at risk.One thing this does not do:
Array_new()still leaves its capacity uninitialised. That is now unreachable rather than fixed, and I've said so in the commit rather than claiming more than the change earns.Upstream wrote this for the empty-root case (no ROMs, Tools hidden); it covers the ordinary empty
Roms/folder #6 describes by the same route. #1 separately sidesteps the Favorites-emptied-from-inside path by backing out to root — these are complementary, not redundant.Testing
Cherry-picks clean onto
main.nextui.cpasses-fsyntax-onlyagainst the desktop platform headers; the only warnings are the pre-existing ones catalogued in #7, including the-Wparentheseshit at line 2681 — none introduced here. Not driven under Xvfb and not tested on hardware.Sequencing note
This lands in
nextui.cwhere #1 and #2 are actively working, and itsBTN_L1/BTN_R1guards sit exactly where #8's letter indicator would go. Worth re-verifying as that stack merges.Why now
Upstream is mid-transition from GPL-3.0 to PolyForm Noncommercial (LoveRetro/NextUI#765). Their
LICENSEis still GPL-3.0 today, so this is adoptable now; code taken after the transition would not be. Original authorship is preserved in the commit trailer.