Skip to content

-#C faults on the first cache entry it names - #1412

Open
xroche wants to merge 2 commits into
masterfrom
fix-1393-savename-null-sback
Open

-#C faults on the first cache entry it names#1412
xroche wants to merge 2 commits into
masterfrom
fix-1393-savename-null-sback

Conversation

@xroche

@xroche xroche commented Aug 24, 2026

Copy link
Copy Markdown
Owner

url_savename() opened by loading sback->lnk into a local that nothing reads until a branch the -#C lister never enters. That lister has no backing and passes NULL, so listing a legacy hts-cache/new.ndx faults on the first entry its pattern matches, before it prints anything. The local now comes from the block that uses it, and the type-probing request further down, the last thing on that path to touch the backing, is skipped when there is none.

That second half is not belt and braces: reading sback->lnk up front is undefined behaviour when it is NULL, so the compiler may delete any NULL test of sback that follows, and at -O2 it does. A mutant carrying the load with the guard in place still crashed, in the guarded branch. The new test drives url_savename() with no backing through a nosback= knob on -#test=savename, and reds on either mutant. End to end, a hand-built legacy ndx over a one-entry cache kills master at htsname.c:413 and lists cleanly once patched.

Closes #1393

xroche and others added 2 commits August 24, 2026 22:17
url_savename() opened by loading sback->lnk into a local that nothing
reads until a branch the -#C lister never enters. That lister has no
backing and passes NULL, so listing a legacy hts-cache/new.ndx faults on
the first entry its pattern matches.

Take the local where the block that uses it starts, and skip the
type-probing request when there is no backing to issue it with. The
unconditional load was also undefined behaviour on a NULL sback, which
let the optimizer drop the later NULL tests as unreachable.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
The self-test's delayed= knob mirrors -%N, not -#N: case 'N' setting
savename_delayed lives in htscoremain.c's '%' family, while '#' is the
separate undocumented debug switch.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
@xroche
xroche enabled auto-merge (squash) August 24, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

url_savename() dereferences the NULL sback that -#C passes it

1 participant