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 #444, Adds JSC 2.1 Static Analysis comments and exposes CF_strnlen #448

Merged
merged 1 commit into from
Jul 2, 2024
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
20 changes: 2 additions & 18 deletions fsw/src/cf_cfdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,22 +299,6 @@ CF_Logical_PduBuffer_t *CF_CFDP_ConstructPduHeader(const CF_Transaction_t *txn,
return ph;
}

/*----------------------------------------------------------------
*
* Internal helper routine only, not part of API.
*
*-----------------------------------------------------------------*/
static inline size_t CF_strnlen(const char *str, size_t maxlen)
{
const char *end = memchr(str, 0, maxlen);
if (end != NULL)
{
/* actual length of string is difference */
maxlen = end - str;
}
return maxlen;
}

/*----------------------------------------------------------------
*
* Application-scope internal function
Expand Down Expand Up @@ -344,10 +328,10 @@ CFE_Status_t CF_CFDP_SendMd(CF_Transaction_t *txn)
/* at this point, need to append filenames into md packet */
/* this does not actually copy here - that is done during encode */
md->source_filename.length =
CF_strnlen(txn->history->fnames.src_filename, sizeof(txn->history->fnames.src_filename));
OS_strnlen(txn->history->fnames.src_filename, sizeof(txn->history->fnames.src_filename));
md->source_filename.data_ptr = txn->history->fnames.src_filename;
md->dest_filename.length =
CF_strnlen(txn->history->fnames.dst_filename, sizeof(txn->history->fnames.dst_filename));
OS_strnlen(txn->history->fnames.dst_filename, sizeof(txn->history->fnames.dst_filename));
md->dest_filename.data_ptr = txn->history->fnames.dst_filename;

CF_CFDP_EncodeMd(ph->penc, md);
Expand Down
5 changes: 4 additions & 1 deletion fsw/src/cf_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,23 @@ CFE_Status_t CF_WriteHistoryEntryToFile(osal_id_t fd, const CF_History_t *histor
{
case 0:
CF_Assert(history->dir < CF_Direction_NUM);
/* SAD: No need to check snprintf return; buffer size is sufficient for the formatted output */
snprintf(linebuf, sizeof(linebuf), "SEQ (%lu, %lu)\tDIR: %s\tPEER %lu\tSTAT: %d\t",
(unsigned long)history->src_eid, (unsigned long)history->seq_num, CF_DSTR[history->dir],
(unsigned long)history->peer_eid, (int)history->txn_stat);
break;
case 1:
/* SAD: No need to check snprintf return; buffer size is sufficient for the formatted output */
snprintf(linebuf, sizeof(linebuf), "SRC: %s\t", history->fnames.src_filename);
break;
case 2:
default:
/* SAD: No need to check snprintf return; buffer size is sufficient for the formatted output */
snprintf(linebuf, sizeof(linebuf), "DST: %s\n", history->fnames.dst_filename);
break;
}

len = strlen(linebuf);
len = OS_strnlen(linebuf, (CF_FILENAME_MAX_LEN * 2) + 128);
ret = CF_WrappedWrite(fd, linebuf, len);
if (ret != len)
{
Expand Down
2 changes: 1 addition & 1 deletion unit-test/stubs/cf_utils_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void UT_DefaultHandler_CF_WriteTxnQueueDataToFile(void *, UT_EntryKey_t, const U
* Generated stub function for CF_FindTransactionBySequenceNumber()
* ----------------------------------------------------
*/
CF_Transaction_t *CF_FindTransactionBySequenceNumber(CF_Channel_t *chan,
CF_Transaction_t *CF_FindTransactionBySequenceNumber(CF_Channel_t * chan,
CF_TransactionSeq_t transaction_sequence_number,
CF_EntityId_t src_eid)
{
Expand Down
Loading