Skip to content

Commit

Permalink
Fix #84, Remove side-effects and superfluous initializations
Browse files Browse the repository at this point in the history
  • Loading branch information
thnkslprpt committed May 31, 2023
1 parent bd4dd1c commit 1b9481c
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 156 deletions.
1 change: 0 additions & 1 deletion .github/workflows/codeql-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
pull_request:


jobs:
codeql:
name: Codeql Analysis
Expand Down
4 changes: 2 additions & 2 deletions fsw/inc/cs_tbldefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ void CS_ProcessNewAppDefinitionTable(const CS_Def_App_Table_Entry_t *DefinitionT
* \param [in] SizeofDefinitionTableEntry The sizeof an entry in the
* definition table
*
* \param [in] SizeofResultsTableEntry The size of an enrty in the
* \param [in] SizeofResultsTableEntry The size of an entry in the
* results table
*
* \param [in] CallBackFunction A pointer to a function used to
Expand Down Expand Up @@ -367,7 +367,7 @@ CFE_Status_t CS_TableInit(CFE_TBL_Handle_t *DefinitionTableHandle, CFE_TBL_Handl
void *DefinitionTblPtr, void *ResultsTblPtr, const uint16 Table,
const char *DefinitionTableName, const char *ResultsTableName, const uint16 NumEntries,
const char *DefinitionTableFileName, const void *DefaultDefTableAddress,
const uint16 SizeofDefinitionTableEntry, const uint16 SizeofResultsTableEntry,
const size_t SizeofDefinitionTableEntry, const size_t SizeofResultsTableEntry,
const CFE_TBL_CallbackFuncPtr_t CallBackFunction);

/**
Expand Down
8 changes: 4 additions & 4 deletions fsw/src/cs_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ CS_AppData_t CS_AppData;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void CS_AppMain(void)
{
CFE_Status_t Result = 0;
CFE_Status_t Result;
CFE_SB_Buffer_t *BufPtr = NULL;

/* Performance Log (start time counter) */
Expand Down Expand Up @@ -147,7 +147,7 @@ void CS_AppMain(void)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
CFE_Status_t CS_AppInit(void)
{
CFE_Status_t Result = CFE_SUCCESS;
CFE_Status_t Result;

/* Register for event services */
Result = CFE_EVS_Register(NULL, 0, 0);
Expand Down Expand Up @@ -264,8 +264,8 @@ CFE_Status_t CS_AppPipe(const CFE_SB_Buffer_t *BufPtr)

void CS_ProcessCmd(const CFE_SB_Buffer_t *BufPtr)
{
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
uint16 CommandCode = 0;
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
CFE_MSG_FcnCode_t CommandCode = 0;

CFE_MSG_GetMsgId(&BufPtr->Msg, &MessageID);

Expand Down
73 changes: 56 additions & 17 deletions fsw/src/cs_app_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void CS_DisableAppCmd(const CS_NoArgsCmd_t *CmdPtr)
{
bool Status;

/* command verification variables */
size_t ExpectedLength = sizeof(CS_NoArgsCmd_t);

/* Verify command packet length */
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
Status = CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength);

if (Status)
{
if (CS_CheckRecomputeOneshot() == false)
Status = CS_CheckRecomputeOneshot();

if (!Status)
{
CS_AppData.HkPacket.AppCSState = CS_STATE_DISABLED;
CS_ZeroAppTempValues();
Expand All @@ -74,13 +80,19 @@ void CS_DisableAppCmd(const CS_NoArgsCmd_t *CmdPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void CS_EnableAppCmd(const CS_NoArgsCmd_t *CmdPtr)
{
bool Status;

/* command verification variables */
size_t ExpectedLength = sizeof(CS_NoArgsCmd_t);

/* Verify command packet length */
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
Status = CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength);

if (Status)
{
if (CS_CheckRecomputeOneshot() == false)
Status = CS_CheckRecomputeOneshot();

if (!Status)
{
CS_AppData.HkPacket.AppCSState = CS_STATE_ENABLED;

Expand All @@ -107,14 +119,19 @@ void CS_ReportBaselineAppCmd(const CS_AppNameCmd_t *CmdPtr)
CS_Res_App_Table_Entry_t *ResultsEntry;
uint32 Baseline;
char Name[OS_MAX_API_NAME];
bool Status;

/* Verify command packet length */
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
Status = CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength);

if (Status)
{
strncpy(Name, CmdPtr->Name, sizeof(Name) - 1);
Name[sizeof(Name) - 1] = '\0';

if (CS_GetAppResTblEntryByName(&ResultsEntry, Name))
Status = CS_GetAppResTblEntryByName(&ResultsEntry, Name);

if (Status)
{
if (ResultsEntry->ComputedYet == true)
{
Expand Down Expand Up @@ -152,18 +169,23 @@ void CS_RecomputeBaselineAppCmd(const CS_AppNameCmd_t *CmdPtr)
CFE_Status_t Status;
CS_Res_App_Table_Entry_t *ResultsEntry;
char Name[OS_MAX_API_NAME];
bool Result;

/* Verify command packet length */

if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
Result = CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength);

if (Result)
{
if (CS_AppData.HkPacket.RecomputeInProgress == false && CS_AppData.HkPacket.OneShotInProgress == false)
{
strncpy(Name, CmdPtr->Name, sizeof(Name) - 1);
Name[sizeof(Name) - 1] = '\0';

/* make sure the entry is a valid number and is defined in the table */
if (CS_GetAppResTblEntryByName(&ResultsEntry, Name))
Result = CS_GetAppResTblEntryByName(&ResultsEntry, Name);

if (Result)
{
/* There is no child task running right now, we can use it*/
CS_AppData.HkPacket.RecomputeInProgress = true;
Expand Down Expand Up @@ -220,16 +242,23 @@ void CS_DisableNameAppCmd(const CS_AppNameCmd_t *CmdPtr)
CS_Res_App_Table_Entry_t *ResultsEntry;
CS_Def_App_Table_Entry_t *DefinitionEntry;
char Name[OS_MAX_API_NAME];
bool Status;

/* Verify command packet length */
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
Status = CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength);

if (Status)
{
if (CS_CheckRecomputeOneshot() == false)
Status = CS_CheckRecomputeOneshot();

if (!Status)
{
strncpy(Name, CmdPtr->Name, sizeof(Name) - 1);
Name[sizeof(Name) - 1] = '\0';

if (CS_GetAppResTblEntryByName(&ResultsEntry, Name))
Status = CS_GetAppResTblEntryByName(&ResultsEntry, Name);

if (Status)
{
ResultsEntry->State = CS_STATE_DISABLED;
ResultsEntry->TempChecksumValue = 0;
Expand All @@ -238,7 +267,9 @@ void CS_DisableNameAppCmd(const CS_AppNameCmd_t *CmdPtr)
CFE_EVS_SendEvent(CS_DISABLE_APP_NAME_INF_EID, CFE_EVS_EventType_INFORMATION,
"Checksumming of app %s is Disabled", Name);

if (CS_GetAppDefTblEntryByName(&DefinitionEntry, Name))
Status = CS_GetAppDefTblEntryByName(&DefinitionEntry, Name);

if (Status)
{
DefinitionEntry->State = CS_STATE_DISABLED;
CS_ResetTablesTblResultEntry(CS_AppData.AppResTablesTblPtr);
Expand All @@ -252,7 +283,6 @@ void CS_DisableNameAppCmd(const CS_AppNameCmd_t *CmdPtr)

CS_AppData.HkPacket.CmdCounter++;
}

else
{
CFE_EVS_SendEvent(CS_DISABLE_APP_UNKNOWN_NAME_ERR_EID, CFE_EVS_EventType_ERROR,
Expand All @@ -276,23 +306,32 @@ void CS_EnableNameAppCmd(const CS_AppNameCmd_t *CmdPtr)
CS_Res_App_Table_Entry_t *ResultsEntry;
CS_Def_App_Table_Entry_t *DefinitionEntry;
char Name[OS_MAX_API_NAME];
bool Status;

/* Verify command packet length */
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
Status = CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength);

if (Status)
{
if (CS_CheckRecomputeOneshot() == false)
Status = CS_CheckRecomputeOneshot();

if (!Status)
{
strncpy(Name, CmdPtr->Name, sizeof(Name) - 1);
Name[sizeof(Name) - 1] = '\0';

if (CS_GetAppResTblEntryByName(&ResultsEntry, Name))
Status = CS_GetAppResTblEntryByName(&ResultsEntry, Name);

if (Status)
{
ResultsEntry->State = CS_STATE_ENABLED;

CFE_EVS_SendEvent(CS_ENABLE_APP_NAME_INF_EID, CFE_EVS_EventType_INFORMATION,
"Checksumming of app %s is Enabled", Name);

if (CS_GetAppDefTblEntryByName(&DefinitionEntry, Name))
Status = CS_GetAppDefTblEntryByName(&DefinitionEntry, Name);

if (Status)
{
DefinitionEntry->State = CS_STATE_ENABLED;
CS_ResetTablesTblResultEntry(CS_AppData.AppResTablesTblPtr);
Expand Down
18 changes: 9 additions & 9 deletions fsw/src/cs_compute.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ CFE_Status_t CS_ComputeTables(CS_Res_Tables_Table_Entry_t *ResultsEntry, uint32
uint32 NewChecksumValue = 0;
CFE_Status_t Status = CFE_SUCCESS;
CFE_Status_t Result = CFE_SUCCESS;
CFE_Status_t ResultShare = 0;
CFE_Status_t ResultGetInfo = 0;
CFE_Status_t ResultGetAddress = 0;
CFE_Status_t ResultShare;
CFE_Status_t ResultGetInfo = 0;
CFE_Status_t ResultGetAddress = 0;

/* variables to get the table address */
CFE_TBL_Handle_t LocalTblHandle = CFE_TBL_BAD_TABLE_HANDLE;
Expand Down Expand Up @@ -313,7 +313,7 @@ CFE_Status_t CS_ComputeApp(CS_Res_App_Table_Entry_t *ResultsEntry, uint32 *Compu
uint32 NewChecksumValue = 0;
CFE_Status_t Status = CFE_SUCCESS;
CFE_Status_t Result;
CFE_Status_t ResultGetResourceID = CS_ERROR;
CFE_Status_t ResultGetResourceID;
CFE_Status_t ResultGetResourceInfo = CS_ERROR;
int32 ResultAddressValid = false;

Expand Down Expand Up @@ -781,11 +781,11 @@ void CS_RecomputeTablesChildTask(void)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void CS_OneShotChildTask(void)
{
uint32 NewChecksumValue = 0;
uint32 NumBytesRemainingCycles = 0;
uint32 NumBytesThisCycle = 0;
cpuaddr FirstAddrThisCycle = 0;
uint32 MaxBytesPerCycle = 0;
uint32 NewChecksumValue;
uint32 NumBytesRemainingCycles;
uint32 NumBytesThisCycle;
cpuaddr FirstAddrThisCycle;
uint32 MaxBytesPerCycle;

NewChecksumValue = 0;
NumBytesRemainingCycles = CS_AppData.HkPacket.LastOneShotSize;
Expand Down
1 change: 0 additions & 1 deletion fsw/src/cs_compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
* function is used to compute checksums for EEPROM, Memory, the
* OS code segment and the cFE core code segment
*
*
* \par Assumptions, External Events, and Notes:
* None
*
Expand Down
24 changes: 12 additions & 12 deletions fsw/src/cs_eeprom_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ void CS_ReportBaselineEntryIDEepromCmd(const CS_EntryCmd_t *CmdPtr)
/* command verification variables */
size_t ExpectedLength = sizeof(CS_EntryCmd_t);

uint32 Baseline = 0;
uint16 EntryID = 0;
uint16 State = CS_STATE_EMPTY;
uint32 Baseline;
uint16 EntryID;
uint16 State = CS_STATE_EMPTY;
CS_Res_EepromMemory_Table_Entry_t ResultsEntry;

/* Verify command packet length */
Expand Down Expand Up @@ -169,9 +169,9 @@ void CS_RecomputeBaselineEepromCmd(const CS_EntryCmd_t *CmdPtr)
size_t ExpectedLength = sizeof(CS_EntryCmd_t);

CFE_ES_TaskId_t ChildTaskID = CFE_ES_TASKID_UNDEFINED;
CFE_Status_t Status = CS_ERROR;
uint16 EntryID = 0;
uint16 State = CS_STATE_EMPTY;
CFE_Status_t Status;
uint16 EntryID;
uint16 State = CS_STATE_EMPTY;

/* Verify command packet length */
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
Expand Down Expand Up @@ -252,8 +252,8 @@ void CS_EnableEntryIDEepromCmd(const CS_EntryCmd_t *CmdPtr)
size_t ExpectedLength = sizeof(CS_EntryCmd_t);

CS_Res_EepromMemory_Table_Entry_t *ResultsEntry = NULL;
uint16 EntryID = 0;
uint16 State = CS_STATE_EMPTY;
uint16 EntryID;
uint16 State = CS_STATE_EMPTY;

/* Verify command packet length */
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
Expand Down Expand Up @@ -318,8 +318,8 @@ void CS_DisableEntryIDEepromCmd(const CS_EntryCmd_t *CmdPtr)
size_t ExpectedLength = sizeof(CS_EntryCmd_t);

CS_Res_EepromMemory_Table_Entry_t *ResultsEntry = NULL;
uint16 EntryID = 0;
uint16 State = CS_STATE_EMPTY;
uint16 EntryID;
uint16 State = CS_STATE_EMPTY;

/* Verify command packet length */
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
Expand Down Expand Up @@ -387,8 +387,8 @@ void CS_GetEntryIDEepromCmd(const CS_GetEntryIDCmd_t *CmdPtr)
size_t ExpectedLength = sizeof(CS_GetEntryIDCmd_t);

CS_Res_EepromMemory_Table_Entry_t *StartOfResultsTable = NULL;
uint16 Loop = 0;
bool EntryFound = false;
uint16 Loop;
bool EntryFound = false;
CS_Res_EepromMemory_Table_Entry_t ResultsEntry;

/* Verify command packet length */
Expand Down
6 changes: 3 additions & 3 deletions fsw/src/cs_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
CFE_Status_t CS_SbInit(void)
{
CFE_Status_t Result = CFE_SUCCESS;
CFE_Status_t Result;

/* Initialize app configuration data */
strncpy(CS_AppData.PipeName, CS_CMD_PIPE_NAME, CS_CMD_PIPE_NAME_LEN);
Expand Down Expand Up @@ -99,7 +99,7 @@ CFE_Status_t CS_SbInit(void)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
CFE_Status_t CS_InitAllTables(void)
{
CFE_Status_t ResultInit = CFE_SUCCESS;
CFE_Status_t ResultInit;

ResultInit = CS_TableInit(&CS_AppData.DefEepromTableHandle, &CS_AppData.ResEepromTableHandle,
(void *)&CS_AppData.DefEepromTblPtr, (void *)&CS_AppData.ResEepromTblPtr, CS_EEPROM_TABLE,
Expand Down Expand Up @@ -174,7 +174,7 @@ CFE_Status_t CS_InitAllTables(void)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void CS_InitSegments(void)
{
int32 ResultSegment = OS_SUCCESS;
int32 ResultSegment;
uint32 CFESize;
cpuaddr CFEAddress;
uint32 KernelSize;
Expand Down
Loading

0 comments on commit 1b9481c

Please sign in to comment.