Skip to content

Conversation

@thnkslprpt
Copy link
Contributor

Checklist

Describe the contribution

Testing performed
GitHub CI actions all passing successfully (incl. Build + Run, Coverage/Functional Tests etc.).
Local testing to confirm net coverage unchanged and test commands also fine.

Expected behavior changes
No change to behavior.
Function is cleaner/simpler which eases future maintenance.

System(s) tested on
Debian GNU/Linux 11 (bullseye)
Current main branch of cFS bundle.

Contributor Info
Avi Weiss @thnkslprpt

Comment on lines 177 to 204
for (TblIndx = 0; CFE_TBL_CmdHandlerTbl[TblIndx].MsgTypes != CFE_TBL_TERM_MSGTYPE; TblIndx++)
{
/* Point to next entry in Command Handler Table */
TblIndx++;

/* Check to see if we found a matching Message ID */
if (CFE_SB_MsgId_Equal(CFE_TBL_CmdHandlerTbl[TblIndx].MsgId, MessageID) &&
(CFE_TBL_CmdHandlerTbl[TblIndx].MsgTypes != CFE_TBL_TERM_MSGTYPE))
if (CFE_SB_MsgId_Equal(CFE_TBL_CmdHandlerTbl[TblIndx].MsgId, MessageID))
{
/* Flag any found message IDs so that if there is an error, */
/* we can determine if it was a bad message ID or bad command code */
FoundMsg = true;

/* If entry in the Command Handler Table is a command entry, */
/* then check for a matching command code */
if (CFE_TBL_CmdHandlerTbl[TblIndx].MsgTypes == CFE_TBL_CMD_MSGTYPE)
{
if (CFE_TBL_CmdHandlerTbl[TblIndx].CmdCode == CommandCode)
{
/* Found matching message ID and Command Code */
FoundMatch = true;
break;
}
}
else /* Message is not a command message with specific command code */
{
/* Automatically assume a match when legit */
/* Message ID is all that is required */
/* Automatically assume a match when legit Message ID is all that is required */
FoundMatch = true;
break;
}
}
} while ((!FoundMatch) && (CFE_TBL_CmdHandlerTbl[TblIndx].MsgTypes != CFE_TBL_TERM_MSGTYPE));
}

/* If we failed to find a match, return a negative index */
if (!FoundMatch)
if (FoundMatch)
{
Result = TblIndx;

Check warning

Code scanning / CodeQL

Unbounded loop

This loop does not have a fixed bound.
@thnkslprpt thnkslprpt force-pushed the fix-1519-refactor-SearchCmdHndlrTbl branch from 8466132 to d9b51fb Compare October 26, 2023 15:32
@thnkslprpt thnkslprpt force-pushed the fix-1519-refactor-SearchCmdHndlrTbl branch from d9b51fb to 29b15c8 Compare April 19, 2024 22:20
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.

Refactor CFE_TBL_SearchCmdHndlrTbl to unmix error codes with indexes and simplify loop

1 participant