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 #225, refactor goto statements #269

Merged
merged 1 commit into from
Jul 20, 2022
Merged

Conversation

havencarlson
Copy link
Contributor

Checklist (Please check before submitting)

Describe the contribution
Fix #225, replaced all instances of goto

Testing performed
Ran unit tests

Expected behavior changes
No impact to behavior

System(s) tested on
Ubuntu 18.04

Contributor Info - All information REQUIRED for consideration of pull request
Haven Carlson - NASA

@havencarlson havencarlson added the CCB:Ready Ready for discussion at the Configuration Control Board (CCB) label Jun 22, 2022
@@ -687,7 +681,9 @@
CFE_EVS_SendEvent(CF_EID_ERR_PDU_MD_SHORT, CFE_EVS_EventType_ERROR,
"CF: metadata packet too short: %lu bytes received",
(unsigned long)CF_CODEC_GET_SIZE(ph->pdec));
goto err_out;
++CF_AppData.hk.channel_hk[t->chan_num].counters.recv.error;

Check notice

Code scanning

Unchecked function argument

This use of parameter t has not been checked.
@@ -642,7 +638,8 @@
{
CFE_EVS_SendEvent(CF_EID_ERR_PDU_LARGE_FILE, CFE_EVS_EventType_ERROR,
"CF: pdu with large file bit received (unsupported)");
goto err_out;
++CF_AppData.hk.channel_hk[chan_num].counters.recv.error;

Check notice

Code scanning

Unchecked function argument

This use of parameter chan_num has not been checked.
fsw/src/cf_cfdp.c Fixed Show fixed Hide fixed
Copy link
Contributor

@skliper skliper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preference is for functions to have one exit point if reasonably possible. We don't currently enforce it as a hard rule but should be the goal.

@havencarlson havencarlson force-pushed the fix#225-goto branch 2 times, most recently from 453ae2d to 58e591e Compare June 24, 2022 20:42
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 17 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 17 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 17 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 17 potential problems in the proposed changes. Check the Files changed tab for more details.

@havencarlson havencarlson removed the CCB:Ready Ready for discussion at the Configuration Control Board (CCB) label Jun 29, 2022
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 50 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 64 potential problems in the proposed changes. Check the Files changed tab for more details.

fsw/src/cf_cfdp_s.c Fixed Show fixed Hide fixed
@@ -81,11 +82,11 @@
CF_AppData.config_table->chan[t->chan_num].max_outgoing_messages_per_wakeup))
{
/* no more messages this wakeup allowed */
c->cur = t; /* remember where we were for next time */
goto error_out;
c->cur = t; /* remember where we were for next time */

Check warning

Code scanning / CodeQL-security

Local variable address stored in non-local memory

A stack address which arrived via a [parameter](1) may be assigned to a non-local variable.
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 61 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 61 potential problems in the proposed changes. Check the Files changed tab for more details.

@havencarlson
Copy link
Contributor Author

I believe I got all functions. The only function I wasn't sure what to do with was CF_CFDP_S_Tick() in cf_cfdp_s.c

Copy link
Contributor

@skliper skliper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great progress! See suggestions (happy to chat if it helps.)

*/
fd->data_len = actual_bytes;
fd->data_ptr = data_ptr;
int status;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declare at the top of the function... might also need to initialize it just to squash warnings

@@ -371,7 +373,8 @@ void CF_CFDP_S_SubstateSendMetadata(CF_Transaction_t *t)
(unsigned long)t->history->src_eid, (unsigned long)t->history->seq_num,
t->history->fnames.src_filename);
++CF_AppData.hk.channel_hk[t->chan_num].counters.fault.file_open;
goto err_out;
t->history->cc = CF_CFDP_ConditionCode_FILESTORE_REJECTION;
CF_CFDP_S_Reset(t);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work because the rest of the calls fail on a transaction that was reset? Probably more clear if you set a flag again and only did each of the following calls based on success. Could also just do the reset and filestore rejection once at the end if it wasn't success.

@@ -761,19 +764,19 @@ void CF_CFDP_S_Tick(CF_Transaction_t *t, int *cont /* unused */)

/* no reason to reset this timer, as it isn't used again */
CF_CFDP_S_Reset(t);
goto err_out; /* must exit after reset */
return; /* must exit after reset */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to think more on this one... but I think we can simplify. If the transaction is reset will it skip the if on 792 anyways? Seem like you just need to also skip the finack send if the SendEof return is CF_SendRet_NO_MSG...

@@ -214,7 +214,7 @@ void CF_CList_Traverse(CF_CListNode_t *start, CF_CListFn_t fn, void *context)
}
if (fn(n, context))
{
goto err_out;
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just break?

@@ -262,7 +260,7 @@ void CF_CList_Traverse_R(CF_CListNode_t *end, CF_CListFn_t fn, void *context)

if (fn(n, context))
{
goto err_out;
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just break if you can

fsw/src/cf_app.c Outdated
status = CFE_TBL_Register(&CF_AppData.config_handle, CF_CONFIG_TABLE_NAME, sizeof(CF_ConfigTable_t),
CFE_TBL_OPT_SNGL_BUFFER | CFE_TBL_OPT_LOAD_DUMP, CF_ValidateConfigTable);
if (status != CFE_SUCCESS)
if ((status = CFE_TBL_Register(&CF_AppData.config_handle, CF_CONFIG_TABLE_NAME, sizeof(CF_ConfigTable_t),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preference is to avoid side affects in conditionals... get the status first, then the decision is just status != CFE_SUCCESS (same for similar patterns below)

fsw/src/cf_app.c Outdated
@@ -213,6 +204,7 @@ int32 CF_TableInit(void)
int32 CF_Init(void)
{
int32 status = CFE_SUCCESS;
bool success = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you just use status == CFE_SUCCESS for these? Might be able to replace at least the first decision w/ just an else (maybe more?)

@@ -1233,14 +1256,12 @@ void CF_CFDP_TickTransactions(CF_Channel_t *c)
if (c->tick_type == CF_TickType_TXW_NAK)
break; /* triggers tick type reset below */
else
goto early_exit;
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe set an "early exit" then only reset the tick type below if not an early exit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried to update this, it seemed to break a unit test and I'm not sure why.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try on line 1240 just doing a break; (since below it just breaks or returns), and then move the conditional on 1256 (might need to adjust the comment if it makes sense) to wrap the logic on 1266? Basically you just want to reset the tick type if c->tick_type == CF_TickType_TXW_NAK.

@@ -131,7 +131,7 @@ void CF_CFDP_R2_Complete(CF_Transaction_t *t, int ok_to_send_nak)

if (t->history->cc != CF_CFDP_ConditionCode_NO_ERROR)
{
goto err_out; /* nothing to do here if error cc is set */
return; /* nothing to do here if error cc is set */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just switch to an == and wrap the entire block blow

@@ -1069,7 +1075,7 @@ void CF_CFDP_R_Tick(CF_Transaction_t *t, int *cont /* unused */)
(unsigned long)t->history->src_eid, (unsigned long)t->history->seq_num);
++CF_AppData.hk.channel_hk[t->chan_num].counters.fault.ack_limit;
CF_CFDP_R2_Reset(t);
goto err_out; /* must return after reset */
return; /* must return after reset */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you just need to skip the CF_CFDP_ArmAckTimer... and could let it flow to the end

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 69 potential problems in the proposed changes. Check the Files changed tab for more details.

fsw/src/cf_cfdp_s.c Fixed Show fixed Hide fixed
fsw/src/cf_app.c Fixed Show fixed Hide fixed
fsw/src/cf_app.c Fixed Show fixed Hide fixed
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 69 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 68 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 68 potential problems in the proposed changes. Check the Files changed tab for more details.

fsw/src/cf_app.c Outdated Show resolved Hide resolved
fsw/src/cf_app.c Outdated Show resolved Hide resolved
@@ -1233,14 +1256,12 @@ void CF_CFDP_TickTransactions(CF_Channel_t *c)
if (c->tick_type == CF_TickType_TXW_NAK)
break; /* triggers tick type reset below */
else
goto early_exit;
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try on line 1240 just doing a break; (since below it just breaks or returns), and then move the conditional on 1256 (might need to adjust the comment if it makes sense) to wrap the logic on 1266? Basically you just want to reset the tick type if c->tick_type == CF_TickType_TXW_NAK.

fsw/src/cf_cfdp_s.c Outdated Show resolved Hide resolved
fsw/src/cf_cfdp_s.c Outdated Show resolved Hide resolved
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 68 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 68 potential problems in the proposed changes. Check the Files changed tab for more details.

@skliper skliper requested a review from semaldona July 20, 2022 14:04
@havencarlson havencarlson added the CCB:Ready Ready for discussion at the Configuration Control Board (CCB) label Jul 20, 2022
@dzbaker dzbaker added CCB:Approved and removed CCB:Ready Ready for discussion at the Configuration Control Board (CCB) labels Jul 20, 2022
@dzbaker
Copy link
Contributor

dzbaker commented Jul 20, 2022

CCB 20 Jul 2022: Approved pending final review by @semaldona.

@dzbaker dzbaker merged commit eba87df into nasa:main Jul 20, 2022
@skliper skliper added this to the Draco milestone Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace use of goto, coding standard violation
5 participants