From 290b2ea82a204546e768d19be74fce08ce1ae0f2 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Mon, 16 May 2022 14:13:47 -0600 Subject: [PATCH] Fix #7, Resolve UT static analysis warnings --- unit-test/hk_utils_tests.c | 22 +++++++++++++++++----- unit-test/utilities/hk_test_utils.c | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/unit-test/hk_utils_tests.c b/unit-test/hk_utils_tests.c index dfafc7b..e1ef7b2 100644 --- a/unit-test/hk_utils_tests.c +++ b/unit-test/hk_utils_tests.c @@ -403,16 +403,18 @@ void Test_HK_ProcessNewCopyTable_PoolBufFail(void) char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "HK Processing New Table: ES_GetPoolBuf for size %%d returned 0x%%04X"); - - UT_SetDefaultReturnValue(UT_KEY(CFE_ES_GetPoolBuf), (CFE_SUCCESS - 1)); - hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES]; hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES]; + memset(RtTblPtr, 0, sizeof(RtTblPtr)); + HK_Test_InitGoodCopyTable(CopyTblPtr); + snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, + "HK Processing New Table: ES_GetPoolBuf for size %%d returned 0x%%04X"); + + UT_SetDefaultReturnValue(UT_KEY(CFE_ES_GetPoolBuf), (CFE_SUCCESS - 1)); + /* Act */ ReturnValue = HK_ProcessNewCopyTable(CopyTblPtr, RtTblPtr); @@ -529,6 +531,8 @@ void Test_HK_ProcessNewCopyTable_Success(void) hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES]; hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES]; + memset(RtTblPtr, 0, sizeof(RtTblPtr)); + HK_Test_InitGoodCopyTable(CopyTblPtr); /* Act */ @@ -576,6 +580,8 @@ void Test_HK_ProcessNewCopyTable_Success2(void) hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES]; hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES]; + memset(RtTblPtr, 0, sizeof(RtTblPtr)); + HK_Test_InitGoodCopyTable(CopyTblPtr); CopyTblPtr[1].InputMid = CFE_SB_INVALID_MSG_ID; @@ -623,6 +629,8 @@ void Test_HK_ProcessNewCopyTable_PacketSizeZero(void) hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES]; hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES]; + memset(RtTblPtr, 0, sizeof(RtTblPtr)); + HK_Test_InitGoodCopyTable(CopyTblPtr); CopyTblPtr[1].OutputOffset = 0; @@ -670,6 +678,8 @@ void Test_HK_ProcessNewCopyTable_AllPacketsSizeZero(void) hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES]; hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES]; + memset(RtTblPtr, 0, sizeof(RtTblPtr)); + HK_Test_InitGoodCopyTable(CopyTblPtr); for (i = 0; i < 5; i++) @@ -721,6 +731,8 @@ void Test_HK_ProcessNewCopyTable_EmptyTable(void) hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES]; hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES]; + memset(RtTblPtr, 0, sizeof(RtTblPtr)); + HK_Test_InitEmptyCopyTable(CopyTblPtr); /* Act */ diff --git a/unit-test/utilities/hk_test_utils.c b/unit-test/utilities/hk_test_utils.c index 493185e..eec4fe0 100644 --- a/unit-test/utilities/hk_test_utils.c +++ b/unit-test/utilities/hk_test_utils.c @@ -69,7 +69,7 @@ void UT_Handler_CFE_EVS_SendEvent(void *UserObj, UT_EntryKey_t FuncKey, const UT void UT_Handler_CFE_ES_WriteToSysLog(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context, va_list va) { strncpy(context_CFE_ES_WriteToSysLog.Spec, UT_Hook_GetArgValueByName(Context, "SpecStringPtr", const char *), - CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); + CFE_MISSION_EVS_MAX_MESSAGE_LENGTH - 1); context_CFE_ES_WriteToSysLog.Spec[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH - 1] = '\0'; }