memory safety: prevent duplicate close and invalid pattern reads - #123
Open
KJ7LNW wants to merge 2 commits into
Open
memory safety: prevent duplicate close and invalid pattern reads#123KJ7LNW wants to merge 2 commits into
KJ7LNW wants to merge 2 commits into
Conversation
added 2 commits
July 29, 2026 14:20
c_plot_card is copied when a PL card replaces nec_context::plot_card and when nec_radiation_pattern captures the active card, giving the plot stream shared lifetime across value copies. The prior raw FILE* member let each copy's destructor call fclose independently, producing a duplicate fclose reached while destroying results for decks with PL cards. - store the FILE handle in std::shared_ptr<FILE> with fclose as the deleter, so temporary assignment, context storage, and radiation-pattern storage retain the same stream and only the final reference closes it - obtain the raw handle with get() only at C standard I/O API call sites - default the destructor since the shared_ptr deleter now owns the close Signed-off-by: Eric Wheeler <necpp@z.ewheeler.org>
…read The RP card XNDA field selects power averaging via its fourth digit. Mode A=2 computes only the average power gain and intentionally leaves per-angle presentation arrays unpopulated, but write_to_file_aux() still iterated the full phi range and read those arrays. - add named constant RP_POWER_AVERAGE_ONLY for the A=2 magic value - bound the per-angle output loop to zero iterations when A=2, so the heading and average print without reading an uninitialized polarization-sense value - replace the prior inline magic-number comparison with the named constant for the average-only guard in analyze() Signed-off-by: Eric Wheeler <necpp@z.ewheeler.org>
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.
Description
Copied plot cards shared a raw
FILE*, causing multiple destructors to close the same stream. Average-only radiation patterns also emitted per-angle rows from arrays that mode intentionally leaves uninitialized.This change gives copied plot cards shared ownership of their stream and suppresses per-angle output when the
RPcard requests average-only reporting, while preserving the heading and average summary.Type of Change
Implementation Details
std::shared_ptr<FILE>withfcloseas the deleter.RPaverage-only mode and omit its unpopulated per-angle rows.Testing
necpp_unitandnecpp_smoke_hertzian_dipole(2/2).20-12.nec: plot-current stream ownershipfclosemore than once on it.20-13.nec: near-field stream ownershipfcloseafter another plot-card copy had closed it.15-9a.nec: average-only radiation patternA=2left per-angle arrays unpopulated, but report generation still iterated those rows and read an uninitialized polarization-sense index.Expected average-only summary: