Skip to content

Commit 1b9481c

Browse files
committed
Fix #84, Remove side-effects and superfluous initializations
1 parent bd4dd1c commit 1b9481c

16 files changed

+251
-156
lines changed

.github/workflows/codeql-build.yml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
pull_request:
66

7-
87
jobs:
98
codeql:
109
name: Codeql Analysis

fsw/inc/cs_tbldefs.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ void CS_ProcessNewAppDefinitionTable(const CS_Def_App_Table_Entry_t *DefinitionT
339339
* \param [in] SizeofDefinitionTableEntry The sizeof an entry in the
340340
* definition table
341341
*
342-
* \param [in] SizeofResultsTableEntry The size of an enrty in the
342+
* \param [in] SizeofResultsTableEntry The size of an entry in the
343343
* results table
344344
*
345345
* \param [in] CallBackFunction A pointer to a function used to
@@ -367,7 +367,7 @@ CFE_Status_t CS_TableInit(CFE_TBL_Handle_t *DefinitionTableHandle, CFE_TBL_Handl
367367
void *DefinitionTblPtr, void *ResultsTblPtr, const uint16 Table,
368368
const char *DefinitionTableName, const char *ResultsTableName, const uint16 NumEntries,
369369
const char *DefinitionTableFileName, const void *DefaultDefTableAddress,
370-
const uint16 SizeofDefinitionTableEntry, const uint16 SizeofResultsTableEntry,
370+
const size_t SizeofDefinitionTableEntry, const size_t SizeofResultsTableEntry,
371371
const CFE_TBL_CallbackFuncPtr_t CallBackFunction);
372372

373373
/**

fsw/src/cs_app.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ CS_AppData_t CS_AppData;
5858
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5959
void CS_AppMain(void)
6060
{
61-
CFE_Status_t Result = 0;
61+
CFE_Status_t Result;
6262
CFE_SB_Buffer_t *BufPtr = NULL;
6363

6464
/* Performance Log (start time counter) */
@@ -147,7 +147,7 @@ void CS_AppMain(void)
147147
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
148148
CFE_Status_t CS_AppInit(void)
149149
{
150-
CFE_Status_t Result = CFE_SUCCESS;
150+
CFE_Status_t Result;
151151

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

265265
void CS_ProcessCmd(const CFE_SB_Buffer_t *BufPtr)
266266
{
267-
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
268-
uint16 CommandCode = 0;
267+
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
268+
CFE_MSG_FcnCode_t CommandCode = 0;
269269

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

fsw/src/cs_app_cmds.c

+56-17
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,19 @@
4646
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
4747
void CS_DisableAppCmd(const CS_NoArgsCmd_t *CmdPtr)
4848
{
49+
bool Status;
50+
4951
/* command verification variables */
5052
size_t ExpectedLength = sizeof(CS_NoArgsCmd_t);
5153

5254
/* Verify command packet length */
53-
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
55+
Status = CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength);
56+
57+
if (Status)
5458
{
55-
if (CS_CheckRecomputeOneshot() == false)
59+
Status = CS_CheckRecomputeOneshot();
60+
61+
if (!Status)
5662
{
5763
CS_AppData.HkPacket.AppCSState = CS_STATE_DISABLED;
5864
CS_ZeroAppTempValues();
@@ -74,13 +80,19 @@ void CS_DisableAppCmd(const CS_NoArgsCmd_t *CmdPtr)
7480
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7581
void CS_EnableAppCmd(const CS_NoArgsCmd_t *CmdPtr)
7682
{
83+
bool Status;
84+
7785
/* command verification variables */
7886
size_t ExpectedLength = sizeof(CS_NoArgsCmd_t);
7987

8088
/* Verify command packet length */
81-
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
89+
Status = CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength);
90+
91+
if (Status)
8292
{
83-
if (CS_CheckRecomputeOneshot() == false)
93+
Status = CS_CheckRecomputeOneshot();
94+
95+
if (!Status)
8496
{
8597
CS_AppData.HkPacket.AppCSState = CS_STATE_ENABLED;
8698

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

111124
/* Verify command packet length */
112-
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
125+
Status = CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength);
126+
127+
if (Status)
113128
{
114129
strncpy(Name, CmdPtr->Name, sizeof(Name) - 1);
115130
Name[sizeof(Name) - 1] = '\0';
116131

117-
if (CS_GetAppResTblEntryByName(&ResultsEntry, Name))
132+
Status = CS_GetAppResTblEntryByName(&ResultsEntry, Name);
133+
134+
if (Status)
118135
{
119136
if (ResultsEntry->ComputedYet == true)
120137
{
@@ -152,18 +169,23 @@ void CS_RecomputeBaselineAppCmd(const CS_AppNameCmd_t *CmdPtr)
152169
CFE_Status_t Status;
153170
CS_Res_App_Table_Entry_t *ResultsEntry;
154171
char Name[OS_MAX_API_NAME];
172+
bool Result;
155173

156174
/* Verify command packet length */
157175

158-
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
176+
Result = CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength);
177+
178+
if (Result)
159179
{
160180
if (CS_AppData.HkPacket.RecomputeInProgress == false && CS_AppData.HkPacket.OneShotInProgress == false)
161181
{
162182
strncpy(Name, CmdPtr->Name, sizeof(Name) - 1);
163183
Name[sizeof(Name) - 1] = '\0';
164184

165185
/* make sure the entry is a valid number and is defined in the table */
166-
if (CS_GetAppResTblEntryByName(&ResultsEntry, Name))
186+
Result = CS_GetAppResTblEntryByName(&ResultsEntry, Name);
187+
188+
if (Result)
167189
{
168190
/* There is no child task running right now, we can use it*/
169191
CS_AppData.HkPacket.RecomputeInProgress = true;
@@ -220,16 +242,23 @@ void CS_DisableNameAppCmd(const CS_AppNameCmd_t *CmdPtr)
220242
CS_Res_App_Table_Entry_t *ResultsEntry;
221243
CS_Def_App_Table_Entry_t *DefinitionEntry;
222244
char Name[OS_MAX_API_NAME];
245+
bool Status;
223246

224247
/* Verify command packet length */
225-
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
248+
Status = CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength);
249+
250+
if (Status)
226251
{
227-
if (CS_CheckRecomputeOneshot() == false)
252+
Status = CS_CheckRecomputeOneshot();
253+
254+
if (!Status)
228255
{
229256
strncpy(Name, CmdPtr->Name, sizeof(Name) - 1);
230257
Name[sizeof(Name) - 1] = '\0';
231258

232-
if (CS_GetAppResTblEntryByName(&ResultsEntry, Name))
259+
Status = CS_GetAppResTblEntryByName(&ResultsEntry, Name);
260+
261+
if (Status)
233262
{
234263
ResultsEntry->State = CS_STATE_DISABLED;
235264
ResultsEntry->TempChecksumValue = 0;
@@ -238,7 +267,9 @@ void CS_DisableNameAppCmd(const CS_AppNameCmd_t *CmdPtr)
238267
CFE_EVS_SendEvent(CS_DISABLE_APP_NAME_INF_EID, CFE_EVS_EventType_INFORMATION,
239268
"Checksumming of app %s is Disabled", Name);
240269

241-
if (CS_GetAppDefTblEntryByName(&DefinitionEntry, Name))
270+
Status = CS_GetAppDefTblEntryByName(&DefinitionEntry, Name);
271+
272+
if (Status)
242273
{
243274
DefinitionEntry->State = CS_STATE_DISABLED;
244275
CS_ResetTablesTblResultEntry(CS_AppData.AppResTablesTblPtr);
@@ -252,7 +283,6 @@ void CS_DisableNameAppCmd(const CS_AppNameCmd_t *CmdPtr)
252283

253284
CS_AppData.HkPacket.CmdCounter++;
254285
}
255-
256286
else
257287
{
258288
CFE_EVS_SendEvent(CS_DISABLE_APP_UNKNOWN_NAME_ERR_EID, CFE_EVS_EventType_ERROR,
@@ -276,23 +306,32 @@ void CS_EnableNameAppCmd(const CS_AppNameCmd_t *CmdPtr)
276306
CS_Res_App_Table_Entry_t *ResultsEntry;
277307
CS_Def_App_Table_Entry_t *DefinitionEntry;
278308
char Name[OS_MAX_API_NAME];
309+
bool Status;
279310

280311
/* Verify command packet length */
281-
if (CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength))
312+
Status = CS_VerifyCmdLength(&CmdPtr->CmdHeader.Msg, ExpectedLength);
313+
314+
if (Status)
282315
{
283-
if (CS_CheckRecomputeOneshot() == false)
316+
Status = CS_CheckRecomputeOneshot();
317+
318+
if (!Status)
284319
{
285320
strncpy(Name, CmdPtr->Name, sizeof(Name) - 1);
286321
Name[sizeof(Name) - 1] = '\0';
287322

288-
if (CS_GetAppResTblEntryByName(&ResultsEntry, Name))
323+
Status = CS_GetAppResTblEntryByName(&ResultsEntry, Name);
324+
325+
if (Status)
289326
{
290327
ResultsEntry->State = CS_STATE_ENABLED;
291328

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

295-
if (CS_GetAppDefTblEntryByName(&DefinitionEntry, Name))
332+
Status = CS_GetAppDefTblEntryByName(&DefinitionEntry, Name);
333+
334+
if (Status)
296335
{
297336
DefinitionEntry->State = CS_STATE_ENABLED;
298337
CS_ResetTablesTblResultEntry(CS_AppData.AppResTablesTblPtr);

fsw/src/cs_compute.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ CFE_Status_t CS_ComputeTables(CS_Res_Tables_Table_Entry_t *ResultsEntry, uint32
125125
uint32 NewChecksumValue = 0;
126126
CFE_Status_t Status = CFE_SUCCESS;
127127
CFE_Status_t Result = CFE_SUCCESS;
128-
CFE_Status_t ResultShare = 0;
129-
CFE_Status_t ResultGetInfo = 0;
130-
CFE_Status_t ResultGetAddress = 0;
128+
CFE_Status_t ResultShare;
129+
CFE_Status_t ResultGetInfo = 0;
130+
CFE_Status_t ResultGetAddress = 0;
131131

132132
/* variables to get the table address */
133133
CFE_TBL_Handle_t LocalTblHandle = CFE_TBL_BAD_TABLE_HANDLE;
@@ -313,7 +313,7 @@ CFE_Status_t CS_ComputeApp(CS_Res_App_Table_Entry_t *ResultsEntry, uint32 *Compu
313313
uint32 NewChecksumValue = 0;
314314
CFE_Status_t Status = CFE_SUCCESS;
315315
CFE_Status_t Result;
316-
CFE_Status_t ResultGetResourceID = CS_ERROR;
316+
CFE_Status_t ResultGetResourceID;
317317
CFE_Status_t ResultGetResourceInfo = CS_ERROR;
318318
int32 ResultAddressValid = false;
319319

@@ -781,11 +781,11 @@ void CS_RecomputeTablesChildTask(void)
781781
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
782782
void CS_OneShotChildTask(void)
783783
{
784-
uint32 NewChecksumValue = 0;
785-
uint32 NumBytesRemainingCycles = 0;
786-
uint32 NumBytesThisCycle = 0;
787-
cpuaddr FirstAddrThisCycle = 0;
788-
uint32 MaxBytesPerCycle = 0;
784+
uint32 NewChecksumValue;
785+
uint32 NumBytesRemainingCycles;
786+
uint32 NumBytesThisCycle;
787+
cpuaddr FirstAddrThisCycle;
788+
uint32 MaxBytesPerCycle;
789789

790790
NewChecksumValue = 0;
791791
NumBytesRemainingCycles = CS_AppData.HkPacket.LastOneShotSize;

fsw/src/cs_compute.h

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
* function is used to compute checksums for EEPROM, Memory, the
4141
* OS code segment and the cFE core code segment
4242
*
43-
*
4443
* \par Assumptions, External Events, and Notes:
4544
* None
4645
*

fsw/src/cs_eeprom_cmds.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ void CS_ReportBaselineEntryIDEepromCmd(const CS_EntryCmd_t *CmdPtr)
110110
/* command verification variables */
111111
size_t ExpectedLength = sizeof(CS_EntryCmd_t);
112112

113-
uint32 Baseline = 0;
114-
uint16 EntryID = 0;
115-
uint16 State = CS_STATE_EMPTY;
113+
uint32 Baseline;
114+
uint16 EntryID;
115+
uint16 State = CS_STATE_EMPTY;
116116
CS_Res_EepromMemory_Table_Entry_t ResultsEntry;
117117

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

171171
CFE_ES_TaskId_t ChildTaskID = CFE_ES_TASKID_UNDEFINED;
172-
CFE_Status_t Status = CS_ERROR;
173-
uint16 EntryID = 0;
174-
uint16 State = CS_STATE_EMPTY;
172+
CFE_Status_t Status;
173+
uint16 EntryID;
174+
uint16 State = CS_STATE_EMPTY;
175175

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

254254
CS_Res_EepromMemory_Table_Entry_t *ResultsEntry = NULL;
255-
uint16 EntryID = 0;
256-
uint16 State = CS_STATE_EMPTY;
255+
uint16 EntryID;
256+
uint16 State = CS_STATE_EMPTY;
257257

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

320320
CS_Res_EepromMemory_Table_Entry_t *ResultsEntry = NULL;
321-
uint16 EntryID = 0;
322-
uint16 State = CS_STATE_EMPTY;
321+
uint16 EntryID;
322+
uint16 State = CS_STATE_EMPTY;
323323

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

389389
CS_Res_EepromMemory_Table_Entry_t *StartOfResultsTable = NULL;
390-
uint16 Loop = 0;
391-
bool EntryFound = false;
390+
uint16 Loop;
391+
bool EntryFound = false;
392392
CS_Res_EepromMemory_Table_Entry_t ResultsEntry;
393393

394394
/* Verify command packet length */

fsw/src/cs_init.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
4040
CFE_Status_t CS_SbInit(void)
4141
{
42-
CFE_Status_t Result = CFE_SUCCESS;
42+
CFE_Status_t Result;
4343

4444
/* Initialize app configuration data */
4545
strncpy(CS_AppData.PipeName, CS_CMD_PIPE_NAME, CS_CMD_PIPE_NAME_LEN);
@@ -99,7 +99,7 @@ CFE_Status_t CS_SbInit(void)
9999
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
100100
CFE_Status_t CS_InitAllTables(void)
101101
{
102-
CFE_Status_t ResultInit = CFE_SUCCESS;
102+
CFE_Status_t ResultInit;
103103

104104
ResultInit = CS_TableInit(&CS_AppData.DefEepromTableHandle, &CS_AppData.ResEepromTableHandle,
105105
(void *)&CS_AppData.DefEepromTblPtr, (void *)&CS_AppData.ResEepromTblPtr, CS_EEPROM_TABLE,
@@ -174,7 +174,7 @@ CFE_Status_t CS_InitAllTables(void)
174174
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
175175
void CS_InitSegments(void)
176176
{
177-
int32 ResultSegment = OS_SUCCESS;
177+
int32 ResultSegment;
178178
uint32 CFESize;
179179
cpuaddr CFEAddress;
180180
uint32 KernelSize;

0 commit comments

Comments
 (0)