-
Notifications
You must be signed in to change notification settings - Fork 46
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
Conversation
@@ -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
@@ -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
There was a problem hiding this 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.
453ae2d
to
58e591e
Compare
There was a problem hiding this 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.
There was a problem hiding this 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.
58e591e
to
07f9228
Compare
There was a problem hiding this 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.
There was a problem hiding this 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.
07f9228
to
8dac0a2
Compare
There was a problem hiding this 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.
8dac0a2
to
0012263
Compare
There was a problem hiding this 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.
0012263
to
88d8764
Compare
@@ -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
There was a problem hiding this 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.
88d8764
to
d628409
Compare
There was a problem hiding this 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.
I believe I got all functions. The only function I wasn't sure what to do with was |
There was a problem hiding this 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.)
fsw/src/cf_cfdp_s.c
Outdated
*/ | ||
fd->data_len = actual_bytes; | ||
fd->data_ptr = data_ptr; | ||
int status; |
There was a problem hiding this comment.
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
fsw/src/cf_cfdp_s.c
Outdated
@@ -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); |
There was a problem hiding this comment.
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.
fsw/src/cf_cfdp_s.c
Outdated
@@ -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 */ |
There was a problem hiding this comment.
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...
fsw/src/cf_clist.c
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you just break?
fsw/src/cf_clist.c
Outdated
@@ -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; |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?)
fsw/src/cf_cfdp.c
Outdated
@@ -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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_r.c
Outdated
@@ -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 */ |
There was a problem hiding this comment.
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
fsw/src/cf_cfdp_r.c
Outdated
@@ -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 */ |
There was a problem hiding this comment.
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
d628409
to
9c47813
Compare
There was a problem hiding this 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.
9c47813
to
9d965c4
Compare
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this 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_cfdp.c
Outdated
@@ -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; |
There was a problem hiding this comment.
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.
9d965c4
to
5f6a437
Compare
There was a problem hiding this 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.
5f6a437
to
2c14b77
Compare
There was a problem hiding this 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.
CCB 20 Jul 2022: Approved pending final review by @semaldona. |
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