Skip to content

Cherry-pick two fixes from Rhizomatica's tree: AWGN eval-order UB, missing <cstring> - #6

Open
spinkham wants to merge 2 commits into
bubnikv:masterfrom
spinkham:fix/rhizomatica-cherry-picks
Open

Cherry-pick two fixes from Rhizomatica's tree: AWGN eval-order UB, missing <cstring>#6
spinkham wants to merge 2 commits into
bubnikv:masterfrom
spinkham:fix/rhizomatica-cherry-picks

Conversation

@spinkham

Copy link
Copy Markdown

Two commits cherry-picked verbatim from Rhizomatica/pathsim, authored by Rafael Diniz (authorship preserved; -x markers reference the original hashes). Rhizomatica's tree carries these but doesn't send PRs upstream, so master never got them.

1. build: add missing <cstring> includes — master currently fails to compile on modern GCC (memset undeclared in Delay.cpp/Path.cpp). This is likely why the other open PRs haven't been easy to verify: the tree doesn't build as-is on current toolchains.

2. fix: C++17 evaluation-order bug destroyed the signal in the AWGN stageNoiseGen.cpp:

pInOut[i] = siggain * pInOut[i ++] + acc;

Under C++17 sequencing the RHS (including the i++ side effect) evaluates before the left-hand subscript, so every store lands at pInOut[i+1], overwriting the next input sample before it's read. Any --snr/--awgn10 run produces garbage: measured on current master, a 1 kHz tone through --awgn10 comes out at −24.0 dB SNR with corr(in,out) = −0.001 — the output is uncorrelated noise, not a degraded signal. (The pre-C++17 MSVC build this code was ported from happened to evaluate the subscript first, which is why the original Windows PathSim worked.)

With these two commits on top of master, the same probe measures +10.73 dB SNR in the 3 kHz band, corr(in,out) = +0.95 — matching the documented S/N design within convention slack.

Independent of #3 (the Hilbert quadrature fix) — the branches don't overlap; all three are needed for a fully functional build.

🤖 Generated with Claude Code

rafael2k and others added 2 commits July 28, 2026 11:32
GCC no longer transitively provides memset via the other headers, so
Delay.cpp and Path.cpp failed to compile with 'memset was not declared
in this scope' (observed with GCC 14 / Debian trixie).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit 0d32135)
pInOut[i] = siggain * pInOut[i++] + acc evaluates the RHS (including the
i++ side effect) BEFORE the left-hand subscript under C++17 sequencing
rules, so every store landed at pInOut[i+1], overwriting the next input
sample before it was read.  Any run with --snr produced garbage audio
(an OFDM modem decodes 0 frames from it even at SNR 20 with no fading);
the pre-C++17 MSVC build this was ported from happened to evaluate the
subscript first.  Split the increment onto its own statement.

Found by cross-validating pathsim against Rhizomatica/mercury's Watterson
channel with freedv OFDM data frames as the probe signal.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit f76d1e1)
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.

2 participants