Skip to content

fix(audio): replace unreachable fallback in primaryRateOrder with Q_UNREACHABLE (#3432)#3433

Merged
ten9876 merged 1 commit into
aethersdr:mainfrom
M7HNF-Ian:fix/3432-unreachable-rate-order-fallback
Jun 6, 2026
Merged

fix(audio): replace unreachable fallback in primaryRateOrder with Q_UNREACHABLE (#3432)#3433
ten9876 merged 1 commit into
aethersdr:mainfrom
M7HNF-Ian:fix/3432-unreachable-rate-order-fallback

Conversation

@M7HNF-Ian
Copy link
Copy Markdown
Contributor

The trailing return {internalRate} after both direction/OS switch statements
in primaryRateOrder() is dead code — every TargetOs value is covered in
both the Output and Input branches. It silently masks future omissions: adding
a new TargetOs enum value without updating a switch would compile cleanly
and return the wrong rate list with no diagnostic.

Replace with Q_UNREACHABLE() so the invariant ("every TargetOs value is
handled in both directions") is enforced by the compiler/runtime rather than
papered over with a silent default.

Testing

All 25 audio_format_negotiation_test checks pass (built and run locally on
macOS against the modified AudioFormatNegotiator.cpp).

Closes #3432

…NREACHABLE (aethersdr#3432)

The trailing `return {internalRate}` after both direction/OS switch
statements was dead code — every TargetOs value is covered in both
the Output and Input branches. It silently masked future omissions:
adding a new TargetOs enum value without updating a switch would
compile cleanly and return the wrong rate list.

Replace with Q_UNREACHABLE() so the compiler/runtime enforces the
invariant instead. All 25 audio_format_negotiation_test checks pass.
@M7HNF-Ian M7HNF-Ian requested a review from a team as a code owner June 6, 2026 17:58
Copy link
Copy Markdown
Contributor

@aethersdr-agent aethersdr-agent Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the cleanup, @M7HNF-Ian — the rationale is exactly right. The trailing return {internalRate} was a silent landmine: adding a fourth TargetOs value would compile cleanly and quietly return only the internal rate, breaking the per-OS ladder in a way that no test or warning would catch. Turning it into a hard invariant via Q_UNREACHABLE() is the right move.

A few notes for awareness (none blocking):

  • First Q_UNREACHABLE() in this codebase. I grepped and there are no existing uses. The neighbour toString(TargetOs) (AudioFormatNegotiator.cpp:228) and toString(ResamplerKind) (line 218) still use silent return "?" defaults. That's fine — the divergence is justified because primaryRateOrder() feeds a real negotiation path while the toString defaults are debug-only — but worth flagging in case the project later wants to standardise on one pattern.

  • Q_UNREACHABLE() vs Q_UNREACHABLE_RETURN(...): Qt 6 ships both. Plain Q_UNREACHABLE() should be sufficient with Clang/GCC/MSVC since it expands to __builtin_unreachable() / __assume(0), but if any CI compiler is older or treats the macro defensively, you may see a "control reaches end of non-void function" warning. If that surfaces, swap to Q_UNREACHABLE_RETURN({}) to suppress it without weakening the invariant. Not needed pre-emptively.

  • Test coverage: confirming locally that all 25 audio_format_negotiation_test checks pass is exactly the right validation — the function is pure-policy by design (per the file header comment), so unit tests are the appropriate gate.

LGTM as a defensive correctness improvement. Nice catch.


🤖 aethersdr-agent · cost: $6.9176 · model: claude-opus-4-7

@ten9876 ten9876 self-assigned this Jun 6, 2026
@ten9876 ten9876 merged commit 198f7ce into aethersdr:main Jun 6, 2026
6 checks passed
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.

[audio] AudioFormatNegotiator::primaryRateOrder: add Q_UNREACHABLE on switch fall-through

2 participants