Skip to content

fix(ec): avoid GCC -O3 -Wfree-nonheap-object false positive in BuildTranscript - #800

Merged
got3nks merged 1 commit into
amule-org:masterfrom
mrjimenez:fix/eccrypt-wfree-nonheap-warning
Aug 5, 2026
Merged

fix(ec): avoid GCC -O3 -Wfree-nonheap-object false positive in BuildTranscript#800
got3nks merged 1 commit into
amule-org:masterfrom
mrjimenez:fix/eccrypt-wfree-nonheap-warning

Conversation

@mrjimenez

Copy link
Copy Markdown

Summary

  • A clean release build (GCC 15.3, -O3) emits a -Wfree-nonheap-object warning twice for ECCrypt::BuildTranscript() (once per translation unit it's compiled in).
  • Reproduced in isolation: the warning is triggered specifically by reserve() followed by repeated push_back()/insert() on the same vector — GCC inlines the vector's growth-guard cleanup and loses track of the allocation's provenance, even though capacity is never actually exceeded. Removing reserve() alone also silences it, confirming this is a compiler analysis artifact, not a real bug.
  • Rewrote the function to size the output vector once and fill it by copy (std::copy/std::copy_n) instead of reserve() + growth calls. Single allocation, byte-for-byte identical output, and the pattern that confuses the analyzer is gone rather than merely avoided by luck.

Test plan

  • Full clean rebuild (cmake --build build --clean-first) — zero compiler warnings
  • ctest — all 33 unit tests pass, including ECCryptTest

…ranscript

reserve() followed by repeated push_back()/insert() on the same vector
tricks GCC 15's inlined growth-guard analysis into losing track of the
allocation's provenance, even though capacity is never exceeded. Size
the vector once and fill it by copy instead: same output, one
allocation, and the warning-triggering code pattern is gone.
@mrjimenez
mrjimenez force-pushed the fix/eccrypt-wfree-nonheap-warning branch from 6d08453 to b37af13 Compare August 5, 2026 00:25
@mrjimenez
mrjimenez requested a review from got3nks August 5, 2026 00:43
@got3nks
got3nks merged commit b6f8f2d into amule-org:master Aug 5, 2026
14 checks passed
@got3nks

got3nks commented Aug 5, 2026

Copy link
Copy Markdown

Merged — thanks @mrjimenez. Verified byte-identical across 200k inputs including both sides of the 255-cipher cap, so the transcript format is unchanged.

ECCryptTest had no coverage of BuildTranscript, so the green suite wasn't evidence either way — I'll add a golden-vector test in a follow-up PR.

@mrjimenez
mrjimenez deleted the fix/eccrypt-wfree-nonheap-warning branch August 8, 2026 15:04
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