Skip to content

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

Description

@thnkslprpt

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions