Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #39, Remove initializations causing Cppcheck errors #40

Conversation

thnkslprpt
Copy link
Contributor

@thnkslprpt thnkslprpt commented Nov 7, 2022

Checklist

Describe the contribution
Fixes #39
Note: all are local variables only.
In order of the errors reported in the issue report:

md_cmds.c
In the MD_ProcessStartCmd() function:
int32 Status = CFE_SUCCESS;: Status only has a single use (on line 88) and it is assigned a value prior to this (on line 87), so this can safely be changed from an initialization to a declaration-only.
uint16 TableIndex = 0;: TableIndex is assigned a value (on line 80) before any and all of its references.

In the MD_ProcessStopCmd() function:
int32 Status = CFE_SUCCESS;: Status is assigned a value (on line 155) and is used only once on the next line. Given that this is a void function, there is no issue with this value being returned uninitialized if it doesn't get set somehow during the function logic or anything like that.
uint16 TableIndex = 0;: TableIndex is assigned a value (on line 146) before any and all of its references, so this can safely be converted from an initialization to a declaration-only at the top of the function.

In the MD_ProcessJamCmd() function:
int32 Status = CFE_SUCCESS;: Status is used twice in this function and is assigned a value both times on the immediately preceding line (on line 261, and later on line 358).
MD_DwellControlEntry_t *DwellEntryPtr = 0;: DwellEntryPtr is just initialized to 0, so can't be used in this state anyway. Its variables are actually assigned values on line 246 and both of its uses are after this line and covered by it.
uint16 EntryIndex = 0;: EntryIndex is only used inside the if block which starts on line 241, and is assigned a value prior to any and all of its references on line 244.

In the MD_ProcessSignatureCmd() function:
int32 Status = CFE_SUCCESS;: Status is only used once (on line 458) and is assigned a value on the line immediately before this use.

md_dwell_pkt.c
int32 Result = 0;: Result is only used once (on line 86), and is assigned a value on the immediately preceding line.
uint16 EntryIndex = 0;: EntryIndex is assigned a value (on line 81) before any and all of its references.
uint16 NumDwellAddresses = 0;: NumDwellAddresses is assigned a value (on line 50) before any and all of its references.

md_dwell_tbl.c
int32 Status = CFE_SUCCESS;: Status is assigned a value (on line 192) and is only used in the mutually exclusive if/else block which immediately follows this assignment.

md_utils.c
int32 OS_Status = OS_SUCCESS;: OS_Status is only used once (on line 216) and is assigned a value on the immediately preceding line.

Testing performed
GitHub CI actions (incl. Build + Run, Unit Tests etc.) all passing successfully.

Expected behavior changes
No impact on behavior.
Cppcheck now passes without error again.

Contributor Info
Avi @thnkslprpt

@dzbaker dzbaker requested a review from jphickey January 5, 2023 19:29
@dzbaker dzbaker merged commit 87e0c1f into nasa:main Jan 12, 2023
@thnkslprpt thnkslprpt deleted the fix-39-remove-initializations-causing-cppcheck-failure branch January 12, 2023 21:58
@dmknutsen dmknutsen added this to the Draco milestone Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Cppcheck errors: '[unreadVariable]'
4 participants