-
Notifications
You must be signed in to change notification settings - Fork 206
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 #2386, Split up and simplify control flow in CFE_TBL_Register()
#2387
Fix #2386, Split up and simplify control flow in CFE_TBL_Register()
#2387
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodeQL found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.
Thanks @thnkslprpt !! Good work here, I like this .... sorry things sit so long. Reviewing this now and hopefully we can merge it, as the existing TBL code is really hard to work with. |
580ed70
to
368cdc4
Compare
@jphickey |
while ((AccessIndex != CFE_TBL_END_OF_LIST) && (*TblHandlePtr == CFE_TBL_BAD_TABLE_HANDLE)) | ||
{ | ||
if ((CFE_TBL_Global.Handles[AccessIndex].UsedFlag == true) && | ||
CFE_RESOURCEID_TEST_EQUAL(CFE_TBL_Global.Handles[AccessIndex].AppId, ThisAppId) && | ||
(CFE_TBL_Global.Handles[AccessIndex].RegIndex == *RegIndxPtr)) | ||
{ | ||
*TblHandlePtr = AccessIndex; | ||
} | ||
else | ||
{ | ||
AccessIndex = CFE_TBL_Global.Handles[AccessIndex].NextLink; | ||
} | ||
} |
Check warning
Code scanning / CodeQL-coding-standard
Unbounded loop Warning
* | ||
*-----------------------------------------------------------------*/ | ||
|
||
CFE_Status_t CFE_TBL_RestoreTableDataFromCDS(CFE_TBL_RegistryRec_t *RegRecPtr, const char *AppName, const char *Name, |
Check notice
Code scanning / CodeQL-coding-standard
Function too long Note
* See description in header file for argument/return detail | ||
* | ||
*-----------------------------------------------------------------*/ | ||
CFE_Status_t CFE_TBL_CheckForDuplicateRegistration(int16 *RegIndxPtr, const char *TblName, |
Check notice
Code scanning / CodeQL-coding-standard
Function too long Note
* See description in header file for argument/return detail | ||
* | ||
*-----------------------------------------------------------------*/ | ||
void CFE_TBL_RegisterWithCriticalTableRegistry(CFE_TBL_CritRegRec_t *CritRegRecPtr, CFE_TBL_RegistryRec_t *RegRecPtr, |
Check notice
Code scanning / CodeQL-coding-standard
Long function without assertion Note
* | ||
*-----------------------------------------------------------------*/ | ||
|
||
CFE_Status_t CFE_TBL_RestoreTableDataFromCDS(CFE_TBL_RegistryRec_t *RegRecPtr, const char *AppName, const char *Name, |
Check notice
Code scanning / CodeQL-coding-standard
Long function without assertion Note
* See description in header file for argument/return detail | ||
* | ||
*-----------------------------------------------------------------*/ | ||
CFE_Status_t CFE_TBL_AllocateTableBuffer(CFE_TBL_RegistryRec_t *RegRecPtr, size_t Size) |
Check notice
Code scanning / CodeQL-coding-standard
Long function without assertion Note
* See description in header file for argument/return detail | ||
* | ||
*-----------------------------------------------------------------*/ | ||
CFE_Status_t CFE_TBL_CheckForDuplicateRegistration(int16 *RegIndxPtr, const char *TblName, |
Check notice
Code scanning / CodeQL-coding-standard
Long function without assertion Note
* See description in header file for argument/return detail | ||
* | ||
*-----------------------------------------------------------------*/ | ||
CFE_Status_t CFE_TBL_ValidateTableOptions(const char *Name, uint16 TblOptionFlags) |
Check notice
Code scanning / CodeQL-coding-standard
Long function without assertion Note
* See description in header file for argument/return detail | ||
* | ||
*-----------------------------------------------------------------*/ | ||
CFE_Status_t CFE_TBL_ValidateTableSize(const char *Name, size_t Size, uint16 TblOptionFlags) |
Check notice
Code scanning / CodeQL-coding-standard
Long function without assertion Note
* See description in header file for argument/return detail | ||
* | ||
*-----------------------------------------------------------------*/ | ||
CFE_Status_t CFE_TBL_ValidateTableName(const char *Name) |
Check notice
Code scanning / CodeQL-coding-standard
Long function without assertion Note
I like this a whole lot better than what was in there. It's far more readable and easy to understand what's going on. The cyclic complexity measurement of CFE_TBL_Register() went from 52 to 20 after merging this change (still could be even better, but this is a huge improvement). I've confirmed that everything seems to work as far as functional tests go - the only concern is that there are some missing lines in the coverage. I may be able to address that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fixup/check some coverage tests.
Corrects some missed branches and lines in the unit test
Corrects some missed branches and lines in the unit test
77f3d29
to
4f94df0
Compare
Corrects some missed branches and lines in the unit test
4f94df0
to
ddbf91f
Compare
Corrects some missed branches and lines in the unit test
ddbf91f
to
8962f47
Compare
@@ -3198,14 +3198,14 @@ | |||
UtAssert_StrnCmp(TblInfo1.LastFileLoaded, MyFilename, sizeof(TblInfo1.LastFileLoaded) - 4, "%s == %s, %ld", | |||
TblInfo1.LastFileLoaded, MyFilename, (long)sizeof(TblInfo1.LastFileLoaded) - 4); | |||
|
|||
if(maxPathLenDiff >= 0) | |||
if (maxPathLenDiff >= 0) |
Check warning
Code scanning / CodeQL-security
Comparison result is always the same Warning
Thanks for adding those coverage tests in. |
*Combines:* cFE equuleus-rc1+dev114 sample_app equuleus-rc1+dev46 **Includes:** *cFE* - nasa/cFE#2387 - nasa/cFE#2531 *sample_app* - nasa/sample_app#218 - nasa/sample_app#216 Co-authored by: Joseph Hickey <[email protected]> Co-authored by: Avi Weiss <[email protected]>
*Combines:* cFE equuleus-rc1+dev114 sample_app equuleus-rc1+dev46 **Includes:** *cFE* - nasa/cFE#2387 - nasa/cFE#2531 *sample_app* - nasa/sample_app#218 - nasa/sample_app#216 Co-authored by: Joseph Hickey <[email protected]> Co-authored by: Avi Weiss <[email protected]>
Checklist
Describe the contribution
CFE_TBL_Register()
#2386CFE_TBL_Register
Main change here was to pull out the logical blocks of work into helper functions.
Additional Changes
Name Size Validation:
Simplified the size checks to just a single check and report (old, new). Can revert this change if the extra verbosity is desired.
Previously, if any of the name size checks failed (and
CFE_TBL_ERR_INVALID_SIZE
Status was set), the code would then still run on to verify the specific table options flags (and re-assign another error code on top ofCFE_TBL_ERR_INVALID_SIZE
if this failed). Have updated this logic to only enter theTblOptionsFlags
checks if the size checks pass successfully. No need to continue execution if error status already set.Main Registration Block Control Flow:
Previously the code would search for an access descriptor even if already in error status here. This is unnecessary if already in error status so have changed this conditional to just check for
== CFE_SUCCESS
(link).In 3 locations inside the this same main table registration block there were status guards of the form
if (Status & CFE_SEVERITY_BITMASK) != CFE_SEVERITY_ERROR)
.I have reduced the nesting in this section, and simplified these checks to just check for
== CFE_SUCCESS
. The only non-negative 'warning' status possible there wasCFE_TBL_WARN_DUPLICATE
, which was already being filtered out anyway. Also, these warning (i.e. non-success, non-error) status/return codes are intended to be deprecated anyway.Minor Simplification:
Simplified this true/false assignment to this.
Note there are a few open issues already for specific issues inside
CFE_TBL_Register
:TblName
in TBL reporting when available #1506CFE_ES_GetAppName()
to reduce code duplication inCFE_TBL_Register()
#2280 (this one is fixed by this PR as well)Testing performed
GitHub CI actions all passing successfully (incl. Build + Run, Unit/Functional Tests etc.). Local testing also conducted to confirm all variables and syslog strings printing as expected etc.
Expected behavior changes
Minor control-flow changes noted above. In general this PR will:
System(s) tested on
Debian GNU/Linux 11 (bullseye)
Current main branch of cFS bundle.
Contributor Info
Avi Weiss @thnkslprpt