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 #52, Remove initializations causing Cppcheck errors #53

Conversation

thnkslprpt
Copy link
Contributor

@thnkslprpt thnkslprpt commented Nov 7, 2022

Checklist

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

hs_cmds.c
int32 Status = CFE_SUCCESS;: The only uses of Status are after it has been set, and given that this is a void function, there seems no need to have it initialized to a default value at the top of the function.

hs_custom.c
uint32 j = 0;: j is assigned a value before each use, so this can be changed from an initialization to a declaration.
uint32 ThisValue = 0;: ThisValue is assigned a value before its use in a mutually exclusive if/else statement beginning on line 292. Therefore, this is also safe to change to declaration-only.
uint32 Ordinal = 0;: Ordinal is assigned a value before its first use (on line 327).
uint32 NewOrdinalIndex = 0;: NewOrdinalIndex is assigned a value on line 338 before its first use.

hs_monitors.c
In the HS_MonitorApplications() function:
int32 Status = CFE_SUCCESS;: Status is assigned a value (on line 65) before it is used, and this assignment covers all of its references. Given that this is a void function, there is no issue with someone trying to potentially return Status uninitialized if it doesn't get set somehow during the function logic (similar to the first case for Status in hs_cmds.c).
uint16 ActionType = 0;: ActionType is assigned a value (on line 58) before any and all of its references.

In the HS_MonitorEvent() function:
uint16 ActionType = 0;: ActionType is assigned a value (on line 234) before any and all of its references.

In the HS_ValidateAMTable() function:
int32 EntryResult = 0;: EntryResult is assigned a value (on line 482) before any and all of its references.
uint16 ActionType = 0;: ActionType is assigned a value (on line 479) before any and all of its references.
uint16 CycleCount = 0;: CycleCount is assigned a value (on line 480) before any and all of its references.
uint16 NullTerm = 0;: NullTerm is assigned a value (on line 481) before any and all of its references.

In the HS_ValidateEMTable() function:
int32 EntryResult = 0;: EntryResult is assigned a value (on line 573) before any and all of its references.
uint16 ActionType = 0;: ActionType is assigned a value (on line 570) before any and all of its references.
uint16 EventID = 0;: EventID is assigned a value (on line 571) before any and all of its references.
uint16 NullTerm = 0;: NullTerm is assigned a value (on line 572) before any and all of its references.

In the HS_ValidateMATable() function:
uint16 EnableState = 0;: EnableState is assigned a value (on line 758) before any and all of its references.
int32 EntryResult = 0;: EntryResult is assigned a value (on line 754) before any and all of its references.

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:05
@dzbaker dzbaker merged commit a99b890 into nasa:main Jan 12, 2023
@thnkslprpt thnkslprpt deleted the fix-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