Skip to content

fix: check fclose() return value at all previously-flagged CFUSA-A007 sites - #119

Merged
SoundMatt merged 1 commit into
mainfrom
fix/unchecked-fclose-a007
Aug 14, 2026
Merged

fix: check fclose() return value at all previously-flagged CFUSA-A007 sites#119
SoundMatt merged 1 commit into
mainfrom
fix/unchecked-fclose-a007

Conversation

@SoundMatt

Copy link
Copy Markdown
Owner

Fixes every "unchecked fclose() return value" (CERT-C ERR33-C, CFUSA-A007) finding flagged by GitHub Advanced Security across the 9 files touched by today's ASIL-scaling/MC/DC work — 39 sites total.

What changed

Product code now genuinely handles a close failure:

  • cmd_qualify.c's qt_write_file() propagates it as a real -1 error (its caller already checks for that).
  • cmd_safety_rules.c's comp001_file() and cmd_coverage.c's parse_lcov() log a diagnostic to stderr, since their return value isn't otherwise surfaced by cfusa_walk_sources()'s callers.

Test files use if (fclose(f) != 0) TEST_FAIL_MESSAGE(...) — turning a silently-ignored close failure into an actual test failure, the correct semantic for test code (if closing a file we just wrote to fails, the test should fail, not continue as if nothing happened). This also genuinely satisfies the rule's intent, unlike a bare (void)fclose(f) cast which discards the value without checking it.

Scope

Left the wider pre-existing ~130 unchecked-fclose() sites elsewhere in the codebase (cmd_pr.c, cmd_release.c, cmd_tara.c, cmd_sign.c, and ~20 other test files never touched this session) out of scope — a separate, much larger cleanup unrelated to today's work.

Not a numbered issue — fixed directly on request following a review of GitHub Advanced Security bot comments on today's merged PRs.

Testing

  • ctest: 42/42 passing.
  • cfusa check --dir .: 0 errors (warning count dropped from 1299 to 1260, matching the 39 fixes).
  • cfusa analyze --dir .: zero remaining CFUSA-A007/fclose findings in all 9 targeted files, confirmed via a fresh re-scan.

🤖 Generated with Claude Code

… sites

Fixes every 'unchecked fclose() return value' (CERT-C ERR33-C) finding
across the 9 files touched by today's ASIL-scaling/MC/DC work
(cmd_qualify.c, cmd_safety_rules.c, cmd_coverage.c, test_impact.c,
test_req_trace_cov.c, test_qualify_vv.c, test_coverage_asil.c,
test_cli_commands.c, test_mcdc.c) -- 39 sites total.

Product code (cmd_qualify.c's qt_write_file, cmd_safety_rules.c's
comp001_file, cmd_coverage.c's parse_lcov) now genuinely handles a
close failure: qt_write_file propagates it as a real error (its
caller already checks for -1); the two file-walk callbacks log a
diagnostic to stderr since their return value isn't otherwise
surfaced by cfusa_walk_sources' callers.

Test files use "if (fclose(f) != 0) TEST_FAIL_MESSAGE(...)" -- turning
a silently-ignored close failure into an actual test failure, which is
the correct semantic for test code (if closing a file we just wrote to
fails, the test should fail, not continue as if nothing happened).
This also genuinely satisfies CFUSA-A007's intent, unlike e.g. a bare
(void)fclose(f) cast, which discards the value without checking it.

Left the wider pre-existing ~130 unchecked-fclose sites elsewhere in
the codebase (cmd_pr.c, cmd_release.c, cmd_tara.c, cmd_sign.c, and
~20 other test files never touched this session) out of scope -- a
separate, much larger cleanup unrelated to today's work.

Not a numbered issue -- fixed directly on request following a review
of GitHub Advanced Security bot comments on today's merged PRs.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
@SoundMatt
SoundMatt merged commit 0cfe932 into main Aug 14, 2026
10 checks passed
SoundMatt added a commit that referenced this pull request Aug 14, 2026
Covers three merged-but-unreleased PRs: #119 (unchecked fclose() fixes),
#120 (CFUSA-A006 false-positive fix), #121 (CFUSA-L003 precision +
ASIL-scaled severity).

Also fixes two stale/inaccurate doc claims found while updating docs for
this release:
- docs/standards/misra-c.md and README.md both stated the check exit
  code reflects disposition acceptance. It doesn't -- cfusa check/lint
  never read .fusa-dispositions.json (issue #122). Corrected both to
  state this plainly instead of overclaiming.
- README.md named the dispositions file .cfusa-dispositions.json --
  that's the legacy fallback read path; the file cfusa disposition add
  actually writes is .fusa-dispositions.json.

docs/standards/iso26262.md's "What scales by ASIL today" list gains an
entry for CFUSA-L003's new ASIL-scaled severity (PR #121).

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
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.

1 participant