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

Must 'else if' constructs always have a final 'else'? #378

Open
thnkslprpt opened this issue Jan 27, 2023 · 0 comments
Open

Must 'else if' constructs always have a final 'else'? #378

thnkslprpt opened this issue Jan 27, 2023 · 0 comments

Comments

@thnkslprpt
Copy link
Contributor

thnkslprpt commented Jan 27, 2023

Describe the bug
Do the coding guidelines (or general cFS custom) require all else if constructs to have a final 'catch all' else block?
If so, there are a couple of remaining cases here in PSP that are missing one.

Code snips

if (CFE_PSP_ReservedMemoryMap.BootPtr->ValidityFlag == CFE_PSP_BOOTRECORD_VALID)
{
OS_printf("CFE_PSP: Normal exit from previous cFE instance\n");
}
else if (CFE_PSP_ReservedMemoryMap.BootPtr->ValidityFlag == CFE_PSP_BOOTRECORD_INVALID)
{
OS_printf("CFE_PSP: Abnormal exit from previous cFE instance\n");
}
/*
* determine reset type...
* If not specified at the command line, then check the "boot record"
*/
reset_type = 0;
if (!CommandData.GotResetType)
{
if (CFE_PSP_ReservedMemoryMap.BootPtr->ValidityFlag == CFE_PSP_BOOTRECORD_VALID ||
CFE_PSP_ReservedMemoryMap.BootPtr->ValidityFlag == CFE_PSP_BOOTRECORD_INVALID)
{
reset_type = CFE_PSP_ReservedMemoryMap.BootPtr->NextResetType;
}
}
else if (strncmp("PR", CommandData.ResetType, 2) == 0)
{
reset_type = CFE_PSP_RST_TYPE_PROCESSOR;
}
if (reset_type == CFE_PSP_RST_TYPE_PROCESSOR)

Suggestion
1st case can simply be replaced by an else (there are only 2 options for the validity flag) or just leave as is, but add an empty else at the end to make it explicit).
Screenshot 2023-01-27 14 30 41

Note: there is 1 more case in the test code

Reporter Info
Avi Weiss @thnkslprpt

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

No branches or pull requests

1 participant