Skip to content

fix: initialize variables flagged as uninitialized by static analysis#2761

Open
stark256-spec wants to merge 1 commit into
nasa:devfrom
stark256-spec:fix/uninit-variables
Open

fix: initialize variables flagged as uninitialized by static analysis#2761
stark256-spec wants to merge 1 commit into
nasa:devfrom
stark256-spec:fix/uninit-variables

Conversation

@stark256-spec
Copy link
Copy Markdown

Summary

Fixes #2736

Static analyzer reported several variables passed to functions as output parameters without being explicitly initialized at the point of declaration.

These are not runtime bugs — the called functions properly initialize the outputs via pointer — but the SA tool cannot prove this, generating false-positive warnings. Adding explicit initialization at declaration eliminates the warnings and follows defensive programming practice.

Changes

File Variable Initializer
cfe_tbl_dump.c (TxnOpenTableDumpFile) FileDescriptor OS_OBJECT_ID_UNDEFINED
cfe_tbl_dump.c (WriteSnapshotToFile) FileDescriptor OS_OBJECT_ID_UNDEFINED
cfe_sb_priv.c (ReceiveTxn_PipeHandler) BufDscPtr NULL
es_cds_test.c (TestCDSName) IdByName CFE_ES_CDS_BAD_HANDLE
es_resource_id_test.c (TestAppIDToIndex) TestAppIdx 0
es_resource_id_test.c (TestCounterIDToIndex) CounterIdx 0
sb_pipe_mang_test.c (TestPipeName) PipeNameBuf {0}

Test plan

  • Existing unit and functional tests pass unchanged
  • Static analysis no longer flags these locations

Static analyzer reported several variables that were passed to functions
as output parameters without being explicitly initialized first (issue
nasa#2736). While not runtime bugs (the functions properly initialize these
outputs), adding explicit initialization eliminates false-positive SA
warnings and follows defensive programming practice.

Changes:
- cfe_tbl_dump.c: FileDescriptor = OS_OBJECT_ID_UNDEFINED in both
  CFE_TBL_TxnOpenTableDumpFile and CFE_TBL_WriteSnapshotToFile
- cfe_sb_priv.c: BufDscPtr = NULL in CFE_SB_ReceiveTxn_PipeHandler
- es_cds_test.c: IdByName = CFE_ES_CDS_BAD_HANDLE in TestCDSName
- es_resource_id_test.c: TestAppIdx = 0 in TestAppIDToIndex,
  CounterIdx = 0 in TestCounterIDToIndex
- sb_pipe_mang_test.c: PipeNameBuf = {0} in TestPipeName

Fixes nasa#2736
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.

Uninitialized Variables Pass to Functions / static analysis cleanup

2 participants