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 #75, Use size_t for size variables/parameters + zero-out the gloabl data struct #76

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions fsw/src/md_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ void MD_AppMain(void)
CFE_SB_Buffer_t *BufPtr = NULL;
size_t ActualLength = 0;

MD_AppData.RunStatus = CFE_ES_RunStatus_APP_RUN;

/* Create the first Performance Log entry */
CFE_ES_PerfLogEntry(MD_APPMAIN_PERF_ID);

Expand Down Expand Up @@ -176,8 +174,10 @@ CFE_Status_t MD_AppInit(void)
*/
CFE_Status_t Status = CFE_SUCCESS;

MD_AppData.CmdCounter = 0;
MD_AppData.ErrCounter = 0;
/* Zero out the global data structure */
memset(&MD_AppData, 0, sizeof(MD_AppData));

MD_AppData.RunStatus = CFE_ES_RunStatus_APP_RUN;

/* Initialize local control structures */
MD_InitControlStructures();
Expand Down Expand Up @@ -656,7 +656,7 @@ void MD_HkStatus()
{
uint8 TblIndex;
uint16 MemDwellEnableBits = 0;
MD_HkTlm_t * HkPktPtr = NULL;
MD_HkTlm_t *HkPktPtr = NULL;
MD_DwellPacketControl_t *ThisDwellTablePtr = NULL;

/* Assign pointer used as shorthand to access Housekeeping Packet fields */
Expand Down
15 changes: 8 additions & 7 deletions fsw/src/md_dwell_tbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void MD_CopyUpdatedTbl(MD_DwellTableLoad_t *MD_LoadTablePtr, uint8 TblIndex)
{
uint8 EntryIndex;
cpuaddr ResolvedAddr = 0;
MD_TableLoadEntry_t * ThisLoadEntry = NULL;
MD_TableLoadEntry_t *ThisLoadEntry = NULL;
MD_DwellPacketControl_t *LocalControlStruct = &MD_AppData.MD_DwellTables[TblIndex];

/* Null check on MD_LoadTablePtr not necessary - table passed validation */
Expand Down Expand Up @@ -343,8 +343,8 @@ CFE_Status_t MD_UpdateTableEnabledField(uint16 TableIndex, uint16 FieldValue)
if ((Status != CFE_SUCCESS) && (Status != CFE_TBL_INFO_UPDATED))
{
CFE_EVS_SendEvent(MD_UPDATE_TBL_EN_ERR_EID, CFE_EVS_EventType_ERROR,
"MD_UpdateTableEnabledField, TableIndex %d: CFE_TBL_GetAddress Returned 0x%08x",
(int)TableIndex, (unsigned int)Status);
"%s, TableIndex %d: CFE_TBL_GetAddress Returned 0x%08x", __func__, (int)TableIndex,
(unsigned int)Status);
}
else
{
Expand Down Expand Up @@ -375,8 +375,8 @@ CFE_Status_t MD_UpdateTableDwellEntry(uint16 TableIndex, uint16 EntryIndex, uint
if ((Status != CFE_SUCCESS) && (Status != CFE_TBL_INFO_UPDATED))
{
CFE_EVS_SendEvent(MD_UPDATE_TBL_DWELL_ERR_EID, CFE_EVS_EventType_ERROR,
"MD_UpdateTableDwellEntry, TableIndex %d: CFE_TBL_GetAddress Returned 0x%08x",
(int)TableIndex, (unsigned int)Status);
"%s, TableIndex %d: CFE_TBL_GetAddress Returned 0x%08x", __func__, (int)TableIndex,
(unsigned int)Status);
}
else
{
Expand All @@ -392,7 +392,8 @@ CFE_Status_t MD_UpdateTableDwellEntry(uint16 TableIndex, uint16 EntryIndex, uint
strncpy(EntryPtr->DwellAddress.SymName, NewDwellAddress.SymName, OS_MAX_SYM_LEN - 1);

/* Ensure string is null terminated. */
/* SAD: SymName’s last element is accessed on this line by reference to its max size, greatly reducing an off by one risk */
/* SAD: SymName’s last element is accessed on this line by reference to its max size, greatly reducing an off by
* one risk */
EntryPtr->DwellAddress.SymName[OS_MAX_SYM_LEN - 1] = '\0';

/* Notify Table Services that buffer was modified */
Expand Down Expand Up @@ -421,7 +422,7 @@ CFE_Status_t MD_UpdateTableSignature(uint16 TableIndex, char NewSignature[MD_SIG
if ((Status != CFE_SUCCESS) && (Status != CFE_TBL_INFO_UPDATED))
{
CFE_EVS_SendEvent(MD_UPDATE_TBL_SIG_ERR_EID, CFE_EVS_EventType_ERROR,
"MD_UpdateTableSignature, TableIndex %d: CFE_TBL_GetAddress Returned 0x%08x", (int)TableIndex,
"%s, TableIndex %d: CFE_TBL_GetAddress Returned 0x%08x", __func__, (int)TableIndex,
(unsigned int)Status);
}
else
Expand Down
6 changes: 3 additions & 3 deletions fsw/src/md_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

/******************************************************************************/

bool MD_ValidAddrRange(cpuaddr Addr, uint32 Size)
bool MD_ValidAddrRange(cpuaddr Addr, size_t Size)
{
bool IsValid = false;

Expand Down Expand Up @@ -142,7 +142,7 @@

/******************************************************************************/

bool MD_Verify32Aligned(cpuaddr Address, uint32 Size)
bool MD_Verify32Aligned(cpuaddr Address, size_t Size)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
bool IsAligned;

Expand All @@ -164,7 +164,7 @@

/******************************************************************************/

bool MD_Verify16Aligned(cpuaddr Address, uint32 Size)
bool MD_Verify16Aligned(cpuaddr Address, size_t Size)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
bool IsAligned;

Expand Down
6 changes: 3 additions & 3 deletions fsw/src/md_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ bool MD_ValidEntryId(uint16 EntryId);
* \retval true Address is valid
* \retval false Address is not valid
*/
bool MD_ValidAddrRange(cpuaddr Addr, uint32 Size);
bool MD_ValidAddrRange(cpuaddr Addr, size_t Size);

/**
* \brief Validate Table ID
Expand Down Expand Up @@ -156,7 +156,7 @@ bool MD_ValidFieldLength(uint16 FieldLength);
*
* \sa #MD_Verify16Aligned
*/
bool MD_Verify32Aligned(cpuaddr Address, uint32 Size);
bool MD_Verify32Aligned(cpuaddr Address, size_t Size);

/**
* \brief Verify 16 bit alignment
Expand All @@ -178,7 +178,7 @@ bool MD_Verify32Aligned(cpuaddr Address, uint32 Size);
*
* \sa #MD_Verify32Aligned
*/
bool MD_Verify16Aligned(cpuaddr Address, uint32 Size);
bool MD_Verify16Aligned(cpuaddr Address, size_t Size);

/**
* \brief Resolve symbolic address
Expand Down
12 changes: 7 additions & 5 deletions unit-test/md_app_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ void MD_InitTableServices_Test_TblRecoveredNotValid(void)
UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_TBL_INFO_RECOVERED_TBL);

/* Set to fail condition "GetAddressResult != CFE_TBL_INFO_UPDATED", to
prevent a core dump by assigning MD_LoadTablePtr, and to make MD_TableValidateionFunc() return non-success */
prevent a core dump by assigning MD_LoadTablePtr, and to make MD_TableValidationFunc() return non-success */
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_INFO_UPDATED);

MD_AppData.MD_DwellTables[0].Enabled = MD_DWELL_STREAM_DISABLED;
Expand Down Expand Up @@ -927,7 +927,7 @@ void MD_InitTableServices_Test_DwellStreamEnabled(void)
UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_TBL_INFO_RECOVERED_TBL);

/* Set to fail condition "GetAddressResult != CFE_TBL_INFO_UPDATED", to
prevent a core dump by assigning MD_LoadTablePtr, and to make MD_TableValidateionFunc() return non-success */
prevent a core dump by assigning MD_LoadTablePtr, and to make MD_TableValidationFunc() return non-success */
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_INFO_UPDATED);

LoadTblPtr->Enabled = MD_DWELL_STREAM_ENABLED;
Expand Down Expand Up @@ -986,7 +986,7 @@ void MD_InitTableServices_Test_TblNotRecovered(void)
UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_TBL_INFO_RECOVERED_TBL);

/* Set to fail condition "GetAddressResult != CFE_TBL_INFO_UPDATED", to
prevent a core dump by assigning MD_LoadTablePtr, and to make MD_TableValidateionFunc() return non-success */
prevent a core dump by assigning MD_LoadTablePtr, and to make MD_TableValidationFunc() return non-success */
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_INFO_UPDATED);

LoadTblPtr->Enabled = MD_DWELL_STREAM_ENABLED;
Expand Down Expand Up @@ -1160,6 +1160,7 @@ void MD_ManageDwellTable_Test_UpdatePendingDwellStreamEnabled(void)
uint8 TblIndex = 0;
MD_DwellTableLoad_t LoadTbl;
MD_DwellTableLoad_t *LoadTblPtr = &LoadTbl;
uint8 call_count_MD_StartDwellStream;

/* Set to satisfy condition "Status == CFE_TBL_INFO_UPDATE_PENDING" */
UT_SetDeferredRetcode(UT_KEY(CFE_TBL_GetStatus), 1, CFE_TBL_INFO_UPDATE_PENDING);
Expand All @@ -1183,7 +1184,7 @@ void MD_ManageDwellTable_Test_UpdatePendingDwellStreamEnabled(void)
UtAssert_True(call_count_CFE_EVS_SendEvent == 0, "CFE_EVS_SendEvent was called %u time(s), expected 0",
call_count_CFE_EVS_SendEvent);

uint8 call_count_MD_StartDwellStream = UT_GetStubCount(UT_KEY(MD_StartDwellStream));
call_count_MD_StartDwellStream = UT_GetStubCount(UT_KEY(MD_StartDwellStream));
UtAssert_INT32_EQ(call_count_MD_StartDwellStream, 1);
}

Expand All @@ -1193,6 +1194,7 @@ void MD_ManageDwellTable_Test_UpdatePendingDwellStreamDisabled(void)
uint8 TblIndex = 0;
MD_DwellTableLoad_t LoadTbl;
MD_DwellTableLoad_t *LoadTblPtr = &LoadTbl;
uint8 call_count_MD_StartDwellStream;

/* Set to satisfy condition "Status == CFE_TBL_INFO_UPDATE_PENDING" */
UT_SetDeferredRetcode(UT_KEY(CFE_TBL_GetStatus), 1, CFE_TBL_INFO_UPDATE_PENDING);
Expand All @@ -1218,7 +1220,7 @@ void MD_ManageDwellTable_Test_UpdatePendingDwellStreamDisabled(void)
UtAssert_True(call_count_CFE_EVS_SendEvent == 0, "CFE_EVS_SendEvent was called %u time(s), expected 0",
call_count_CFE_EVS_SendEvent);

uint8 call_count_MD_StartDwellStream = UT_GetStubCount(UT_KEY(MD_StartDwellStream));
call_count_MD_StartDwellStream = UT_GetStubCount(UT_KEY(MD_StartDwellStream));
UtAssert_INT32_EQ(call_count_MD_StartDwellStream, 0);
}

Expand Down
6 changes: 3 additions & 3 deletions unit-test/md_dwell_tbl_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ void MD_UpdateTableEnabledField_Test_Error(void)
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"MD_UpdateTableEnabledField, TableIndex %%d: CFE_TBL_GetAddress Returned 0x%%08x");
"%%s, TableIndex %%d: CFE_TBL_GetAddress Returned 0x%%08x");

/* Set to make CFE_TBL_GetAddress != CFE_SUCCESS */
UT_SetDeferredRetcode(UT_KEY(CFE_TBL_GetAddress), 1, -1);
Expand Down Expand Up @@ -1056,7 +1056,7 @@ void MD_UpdateTableDwellEntry_Test_Error(void)
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"MD_UpdateTableDwellEntry, TableIndex %%d: CFE_TBL_GetAddress Returned 0x%%08x");
"%%s, TableIndex %%d: CFE_TBL_GetAddress Returned 0x%%08x");

NewDwellAddress.Offset = 1;

Expand Down Expand Up @@ -1139,7 +1139,7 @@ void MD_UpdateTableSignature_Test_Error(void)
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"MD_UpdateTableSignature, TableIndex %%d: CFE_TBL_GetAddress Returned 0x%%08x");
"%%s, TableIndex %%d: CFE_TBL_GetAddress Returned 0x%%08x");

/* Set to make CFE_TBL_GetAddress != CFE_SUCCESS */
UT_SetDeferredRetcode(UT_KEY(CFE_TBL_GetAddress), 1, -1);
Expand Down
8 changes: 4 additions & 4 deletions unit-test/md_utils_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void MD_ValidAddrRange_Test_Valid(void)
{
bool Result;
cpuaddr Addr = 1;
uint32 Size = 1;
size_t Size = 1;

/* Execute the function being tested */
Result = MD_ValidAddrRange(Addr, Size);
Expand All @@ -221,7 +221,7 @@ void MD_ValidAddrRange_Test_Invalid(void)
{
bool Result;
cpuaddr Addr = 1;
uint32 Size = 1;
size_t Size = 1;

/* Set to reach "IsValid = false" */
UT_SetDeferredRetcode(UT_KEY(CFE_PSP_MemValidateRange), 1, -1);
Expand Down Expand Up @@ -378,7 +378,7 @@ void MD_Verify32Aligned_Test(void)
{
bool Result;
cpuaddr Addr;
uint32 Size;
size_t Size;

Addr = 0; /* address is aligned */
Size = 4; /* size is aligned */
Expand Down Expand Up @@ -412,7 +412,7 @@ void MD_Verify16Aligned_Test(void)
{
bool Result;
cpuaddr Addr;
uint32 Size;
size_t Size;

Addr = 0; /* address is aligned */
Size = 4; /* size is aligned */
Expand Down
6 changes: 3 additions & 3 deletions unit-test/stubs/md_utils_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool MD_ValidEntryId(uint16 EntryId)
return UT_DEFAULT_IMPL(MD_ValidEntryId) != 0;
}

bool MD_ValidAddrRange(cpuaddr Addr, uint32 Size)
bool MD_ValidAddrRange(cpuaddr Addr, size_t Size)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(MD_ValidAddrRange), Addr);
UT_Stub_RegisterContextGenericArg(UT_KEY(MD_ValidAddrRange), Size);
Expand All @@ -67,14 +67,14 @@ bool MD_ValidFieldLength(uint16 FieldLength)
return UT_DEFAULT_IMPL(MD_ValidFieldLength) != 0;
}

bool MD_Verify32Aligned(cpuaddr Address, uint32 Size)
bool MD_Verify32Aligned(cpuaddr Address, size_t Size)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(MD_Verify32Aligned), Address);
UT_Stub_RegisterContextGenericArg(UT_KEY(MD_Verify32Aligned), Size);
return UT_DEFAULT_IMPL(MD_Verify32Aligned) != 0;
}

bool MD_Verify16Aligned(cpuaddr Address, uint32 Size)
bool MD_Verify16Aligned(cpuaddr Address, size_t Size)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(MD_Verify16Aligned), Address);
UT_Stub_RegisterContextGenericArg(UT_KEY(MD_Verify16Aligned), Size);
Expand Down
Loading