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 #1517, Reformat do/while loop to while (style change only) #2180

Closed

Conversation

thnkslprpt
Copy link
Contributor

@thnkslprpt thnkslprpt commented Oct 25, 2022

Checklist

Describe the contribution

Testing performed
GitHub CI actions (incl. Build + Run, Unit Tests etc.) all passing successfully.

Expected behavior changes
No impact on behavior - code logic essentially unchanged.

Contributor Info
Avi Weiss @thnkslprpt

Comment on lines +489 to +503
while ((RegIndx == CFE_TBL_NOT_FOUND) && (i < (CFE_PLATFORM_TBL_MAX_NUM_TABLES - 1)))
{
/* Point to next record in the Table Registry */
i++;

/* Check to see if the record is currently being used */
if (!CFE_RESOURCEID_TEST_EQUAL(CFE_TBL_Global.Registry[i].OwnerAppId, CFE_TBL_NOT_OWNED))
/* Check to see if the record is currently being used and perform a case-sensitive name comparison */
if (!CFE_RESOURCEID_TEST_EQUAL(CFE_TBL_Global.Registry[i].OwnerAppId, CFE_TBL_NOT_OWNED) &&
strcmp(TblName, CFE_TBL_Global.Registry[i].Name) == 0)
{
/* Perform a case sensitive name comparison */
if (strcmp(TblName, CFE_TBL_Global.Registry[i].Name) == 0)
{
/* If the names match, then return the index */
RegIndx = i;
}
/* If the names match, then return the index */
RegIndx = i;
}
} while ((RegIndx == CFE_TBL_NOT_FOUND) && (i < (CFE_PLATFORM_TBL_MAX_NUM_TABLES - 1)));
else
{
/* Point to next record in the Table Registry */
i++;
}
}

Check warning

Code scanning / CodeQL-coding-standard

Unbounded loop

The loop counter i is not always incremented in the loop body.
@thnkslprpt thnkslprpt force-pushed the fix-1517-reformat-do-while-loop branch from e9f2a78 to 0b00937 Compare March 14, 2023 11:37
@jphickey
Copy link
Contributor

I think the intent here is that if its a common routine, a helper function would be better, rather than repeating the code (the latter is probably how they ended up diverging in the first place)

@thnkslprpt
Copy link
Contributor Author

No longer relevent since #2539

@thnkslprpt thnkslprpt closed this Apr 21, 2024
@thnkslprpt thnkslprpt deleted the fix-1517-reformat-do-while-loop branch April 21, 2024 01:04
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.

Consistent loop implementation in CFE_TBL_FindTableInRegistry and CFE_TBL_FindFreeRegistryEntry
2 participants