Fix #28, Remove initializations causing Cppcheck failure #29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 3for
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 singleif
block.CFE_SB_Buffer_t * NewPacketAddr = 0;
:NewPacketAddr
is only used in theif
block starting on line 192, and it is assigned a value (ofNULL
) 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 toResult
on line 194 and line 229 cover its use in theif
blocks immediately following those assignments.In the
HK_TearDownOldCopyTable()
function:int32 Loop2 = 0;
:Loop2
is used in 2for
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 toResult
on line 304 covers its use in the mutually exclusiveif
/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