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 #28, Remove initializations causing Cppcheck failure #29

Conversation

thnkslprpt
Copy link
Contributor

@thnkslprpt thnkslprpt commented Nov 7, 2022

Checklist

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

In the HK_ProcessIncomingHkData() function:
int32 LastByteAccessed = 0;: LastByteAccessed is assigned a value on line 72, and is only used once on the line immediately after that, so the initialization at the top of the function is redundant.

In the HK_ProcessNewCopyTable() function:
int32 Loop2 = 0;: Loop2 is used in 3 for loops, and it is assigned a value (of zero) each time in the init-statement. Therefore the initialization at the top of the function can safely be changed to a declaration-only.
CFE_SB_MsgId_t MidOfThisPacket = CFE_SB_INVALID_MSG_ID;: MidOfThisPacket is assigned a value on line 167 and is used twice after that in 2 loops, both of which are covered by the assignment on line 167.
int32 SizeOfThisPacket = 0;: SizeOfThisPacket is assigned a value on line 168 and is used twice after that in 2 loops, both of which are covered by the assignment on line 168.
int32 FurthestByteFromThisEntry = 0;: FurthestByteFromThisEntry is assigned a value on line 180 and is only used immediately after that in a single if block.
CFE_SB_Buffer_t * NewPacketAddr = 0;: NewPacketAddr is only used in the if block starting on line 192, and it is assigned a value (of NULL) immediately preceding that line, thus the initialization at the top of the function is redundant (and we can change it to a declaration-only).
int32 Result = CFE_SUCCESS;: The assignment to Result on line 194 and line 229 cover its use in the if blocks immediately following those assignments.

In the HK_TearDownOldCopyTable() function:
int32 Loop2 = 0;: Loop2 is used in 2 for loops, and it is assigned a value (of zero) each time in the init-statement. Therefore the initialization at the top of the function can safely be changed to a declaration-only.
CFE_SB_MsgId_t MidOfThisPacket = CFE_SB_INVALID_MSG_ID;: MidOfThisPacket is only used once in this function (on line 313) and it is assigned a value preceding that use on line 301.
int32 Result = CFE_SUCCESS;: The assignment to Result on line 304 covers its use in the mutually exclusive if/else block starting on the next line, which is the only place it is used in this function.

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 merged commit 518bea7 into nasa:main Jan 12, 2023
@thnkslprpt thnkslprpt deleted the fix-28-remove-initializations-causing-cppcheck-failure branch January 12, 2023 21:57
@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