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 #285, flatten logic in CF_CFDP_InitEngine() to fix bug #286

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 41 additions & 45 deletions fsw/src/cf_cfdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,58 +1031,54 @@ int32 CF_CFDP_InitEngine(void)
"CF: failed to create pipe %s, returned 0x%08lx", nbuf, (unsigned long)ret);
break;
}
else

ret = CFE_SB_SubscribeLocal(CFE_SB_ValueToMsgId(CF_AppData.config_table->chan[i].mid_input),
CF_AppData.engine.channels[i].pipe,
CF_AppData.config_table->chan[i].pipe_depth_input);
if (ret != CFE_SUCCESS)
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_SUB, CFE_EVS_EventType_ERROR,

Check warning

Code scanning / CodeQL-coding-standard

Unchecked return value

The return value of non-void function [CFE_EVS_SendEvent](1) is not checked.
"CF: failed to subscribe to MID 0x%lx, returned 0x%08lx",
(unsigned long)CF_AppData.config_table->chan[i].mid_input, (unsigned long)ret);
break;
}

if (CF_AppData.config_table->chan[i].sem_name[0])
{
ret = CFE_SB_SubscribeLocal(CFE_SB_ValueToMsgId(CF_AppData.config_table->chan[i].mid_input),
CF_AppData.engine.channels[i].pipe,
CF_AppData.config_table->chan[i].pipe_depth_input);
if (ret != CFE_SUCCESS)
ret = OS_CountSemGetIdByName(&CF_AppData.engine.channels[i].sem_id,
CF_AppData.config_table->chan[i].sem_name);
if (ret != OS_SUCCESS)
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_SUB, CFE_EVS_EventType_ERROR,
"CF: failed to subscribe to MID 0x%lx, returned 0x%08lx",
(unsigned long)CF_AppData.config_table->chan[i].mid_input, (unsigned long)ret);
CFE_EVS_SendEvent(CF_EID_ERR_INIT_SEM, CFE_EVS_EventType_ERROR,

Check warning

Code scanning / CodeQL-coding-standard

Unchecked return value

The return value of non-void function [CFE_EVS_SendEvent](1) is not checked.
"CF: failed to get sem id for name %s, error=%ld",
CF_AppData.config_table->chan[i].sem_name, (long)ret);
break;
}
else if (CF_AppData.config_table->chan[i].sem_name[0])
{
ret = OS_CountSemGetIdByName(&CF_AppData.engine.channels[i].sem_id,
CF_AppData.config_table->chan[i].sem_name);
if (ret != OS_SUCCESS)
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_SEM, CFE_EVS_EventType_ERROR,
"CF: failed to get sem id for name %s, error=%ld",
CF_AppData.config_table->chan[i].sem_name, (long)ret);
break;
}
else
{
for (j = 0; j < CF_NUM_TRANSACTIONS_PER_CHANNEL; ++j, ++t)
{
int k;

t->chan_num = i;
CF_FreeTransaction(t);

for (k = 0; k < CF_Direction_NUM; ++k, ++c)
{
CF_Assert((chunk_mem_offset + CF_DIR_MAX_CHUNKS[k][i]) <= CF_NUM_CHUNKS_ALL_CHANNELS);
CF_ChunkListInit(&c->chunks, CF_DIR_MAX_CHUNKS[k][i],
&CF_AppData.engine.chunk_mem[chunk_mem_offset]);
chunk_mem_offset += CF_DIR_MAX_CHUNKS[k][i];
CF_CList_InitNode(&c->cl_node);
CF_CList_InsertBack(&CF_AppData.engine.channels[i].cs[k], &c->cl_node);
}
}
}

for (j = 0; j < CF_NUM_HISTORIES_PER_CHANNEL; ++j)
{
CF_History_t *h = &CF_AppData.engine.histories[(i * CF_NUM_HISTORIES_PER_CHANNEL) + j];
CF_CList_InitNode(&h->cl_node);
CF_CList_InsertBack_Ex(&CF_AppData.engine.channels[i], CF_QueueIdx_HIST_FREE, &h->cl_node);
}
}
for (j = 0; j < CF_NUM_TRANSACTIONS_PER_CHANNEL; ++j, ++t)

Check notice

Code scanning / CodeQL-coding-standard

AV Rule 168

AV Rule 168: The comma operator shall not be used.
{
int k;

Check notice

Code scanning / CodeQL-coding-standard

Use of basic integral type

k uses the basic integral type int rather than a typedef with size and signedness.

t->chan_num = i;
CF_FreeTransaction(t);

for (k = 0; k < CF_Direction_NUM; ++k, ++c)

Check notice

Code scanning / CodeQL-coding-standard

AV Rule 168

AV Rule 168: The comma operator shall not be used.
{
CF_Assert((chunk_mem_offset + CF_DIR_MAX_CHUNKS[k][i]) <= CF_NUM_CHUNKS_ALL_CHANNELS);
CF_ChunkListInit(&c->chunks, CF_DIR_MAX_CHUNKS[k][i], &CF_AppData.engine.chunk_mem[chunk_mem_offset]);
chunk_mem_offset += CF_DIR_MAX_CHUNKS[k][i];
CF_CList_InitNode(&c->cl_node);
CF_CList_InsertBack(&CF_AppData.engine.channels[i].cs[k], &c->cl_node);
}
}

for (j = 0; j < CF_NUM_HISTORIES_PER_CHANNEL; ++j)
{
CF_History_t *h = &CF_AppData.engine.histories[(i * CF_NUM_HISTORIES_PER_CHANNEL) + j];
CF_CList_InitNode(&h->cl_node);
CF_CList_InsertBack_Ex(&CF_AppData.engine.channels[i], CF_QueueIdx_HIST_FREE, &h->cl_node);
}
}

if (ret == CFE_SUCCESS)
Expand Down
1 change: 1 addition & 0 deletions unit-test/cf_cfdp_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ void Test_CF_CFDP_InitEngine(void)
UT_CFDP_SetupBasicTestState(UT_CF_Setup_NONE, NULL, NULL, NULL, NULL, &config);
UtAssert_INT32_EQ(CF_CFDP_InitEngine(), 0);
UtAssert_BOOL_TRUE(CF_AppData.engine.enabled);
UtAssert_STUB_COUNT(CF_FreeTransaction, CF_NUM_TRANSACTIONS_PER_CHANNEL);

/* nominal call, with sem */
UT_CFDP_SetupBasicTestState(UT_CF_Setup_NONE, NULL, NULL, NULL, NULL, &config);
Expand Down