Skip to content

Commit

Permalink
Fix nasa#1984, avoid aliasing warnings
Browse files Browse the repository at this point in the history
Use an actual `void*` value when invoking functions
that output an opaque pointer value.  If necessary
the value of this pointer can then be assigned to
the real pointer type to dereference.
  • Loading branch information
jphickey committed Oct 1, 2021
1 parent 98f78e8 commit 2f4a7fd
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 70 deletions.
25 changes: 17 additions & 8 deletions modules/cfe_testcase/src/tbl_content_mang_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void TestLoad(void)
TBL_TEST_Table_t TestTable = {0xd00d, 0xdad};
TBL_TEST_Table_t *TablePtr;
CFE_TBL_Handle_t OtherHandle;
void * TempPtr;

UtPrintf("Testing: CFE_TBL_Load");

Expand Down Expand Up @@ -107,7 +108,8 @@ void TestLoad(void)
UtAssert_INT32_EQ(CFE_TBL_Load(CFE_FT_Global.TblHandle, CFE_TBL_SRC_FILE, TESTTBL_NOMINAL_FILE), CFE_SUCCESS);

/* confirm content (football) */
UtAssert_INT32_EQ(CFE_TBL_GetAddress((void **)&TablePtr, CFE_FT_Global.TblHandle), CFE_TBL_INFO_UPDATED);
UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TempPtr, CFE_FT_Global.TblHandle), CFE_TBL_INFO_UPDATED);
TablePtr = TempPtr;
UtAssert_UINT32_EQ(TablePtr->Int1, 0xf007);
UtAssert_UINT32_EQ(TablePtr->Int2, 0xba11);
UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(CFE_FT_Global.TblHandle), CFE_SUCCESS);
Expand All @@ -117,7 +119,8 @@ void TestLoad(void)
CFE_TBL_ERR_FILE_TOO_LARGE);

/* confirm content again (note content should not have been updated) */
UtAssert_INT32_EQ(CFE_TBL_GetAddress((void **)&TablePtr, CFE_FT_Global.TblHandle), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TempPtr, CFE_FT_Global.TblHandle), CFE_SUCCESS);
TablePtr = TempPtr;
UtAssert_UINT32_EQ(TablePtr->Int1, 0xf007);
UtAssert_UINT32_EQ(TablePtr->Int2, 0xba11);
UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(CFE_FT_Global.TblHandle), CFE_SUCCESS);
Expand All @@ -126,7 +129,8 @@ void TestLoad(void)
UtAssert_INT32_EQ(CFE_TBL_Load(CFE_FT_Global.TblHandle, CFE_TBL_SRC_FILE, TESTTBL_ALTERNATE_FILE), CFE_SUCCESS);

/* confirm content again (changed to alternate data) */
UtAssert_INT32_EQ(CFE_TBL_GetAddress((void **)&TablePtr, CFE_FT_Global.TblHandle), CFE_TBL_INFO_UPDATED);
UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TempPtr, CFE_FT_Global.TblHandle), CFE_TBL_INFO_UPDATED);
TablePtr = TempPtr;
UtAssert_UINT32_EQ(TablePtr->Int1, 0xdead);
UtAssert_UINT32_EQ(TablePtr->Int2, 0xbeef);
UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(CFE_FT_Global.TblHandle), CFE_SUCCESS);
Expand All @@ -136,7 +140,8 @@ void TestLoad(void)
CFE_TBL_ERR_LOAD_INCOMPLETE);

/* confirm content again (should not be changed) */
UtAssert_INT32_EQ(CFE_TBL_GetAddress((void **)&TablePtr, CFE_FT_Global.TblHandle), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TempPtr, CFE_FT_Global.TblHandle), CFE_SUCCESS);
TablePtr = TempPtr;
UtAssert_UINT32_EQ(TablePtr->Int1, 0xdead);
UtAssert_UINT32_EQ(TablePtr->Int2, 0xbeef);
UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(CFE_FT_Global.TblHandle), CFE_SUCCESS);
Expand All @@ -145,13 +150,15 @@ void TestLoad(void)
UtAssert_INT32_EQ(CFE_TBL_Load(OtherHandle, CFE_TBL_SRC_FILE, TESTTBL_OTHERTBL_FILE), CFE_SUCCESS);

/* confirm content of first table again (should not be changed) */
UtAssert_INT32_EQ(CFE_TBL_GetAddress((void **)&TablePtr, CFE_FT_Global.TblHandle), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TempPtr, CFE_FT_Global.TblHandle), CFE_SUCCESS);
TablePtr = TempPtr;
UtAssert_UINT32_EQ(TablePtr->Int1, 0xdead);
UtAssert_UINT32_EQ(TablePtr->Int2, 0xbeef);
UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(CFE_FT_Global.TblHandle), CFE_SUCCESS);

/* confirm content of other table (boatload) */
UtAssert_INT32_EQ(CFE_TBL_GetAddress((void **)&TablePtr, OtherHandle), CFE_TBL_INFO_UPDATED);
UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TempPtr, OtherHandle), CFE_TBL_INFO_UPDATED);
TablePtr = TempPtr;
UtAssert_UINT32_EQ(TablePtr->Int1, 0xb0a7);
UtAssert_UINT32_EQ(TablePtr->Int2, 0x10ad);
UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(OtherHandle), CFE_SUCCESS);
Expand All @@ -161,7 +168,8 @@ void TestLoad(void)

/* confirm content again (reported as updated from partial load) */
/* Should have updated the first word only */
UtAssert_INT32_EQ(CFE_TBL_GetAddress((void **)&TablePtr, CFE_FT_Global.TblHandle), CFE_TBL_INFO_UPDATED);
UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TempPtr, CFE_FT_Global.TblHandle), CFE_TBL_INFO_UPDATED);
TablePtr = TempPtr;
UtAssert_UINT32_EQ(TablePtr->Int1, 0x5555);
UtAssert_UINT32_EQ(TablePtr->Int2, 0xbeef);
UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(CFE_FT_Global.TblHandle), CFE_SUCCESS);
Expand All @@ -171,7 +179,8 @@ void TestLoad(void)

/* confirm content again (reported as updated from partial load) */
/* Should have updated the second word only */
UtAssert_INT32_EQ(CFE_TBL_GetAddress((void **)&TablePtr, CFE_FT_Global.TblHandle), CFE_TBL_INFO_UPDATED);
UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TempPtr, CFE_FT_Global.TblHandle), CFE_TBL_INFO_UPDATED);
TablePtr = TempPtr;
UtAssert_UINT32_EQ(TablePtr->Int1, 0x5555);
UtAssert_UINT32_EQ(TablePtr->Int2, 0x6666);
UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(CFE_FT_Global.TblHandle), CFE_SUCCESS);
Expand Down
39 changes: 22 additions & 17 deletions modules/core_api/ut-stubs/src/cfe_es_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,18 @@ void UT_DefaultHandler_CFE_ES_GetAppID(void *UserObj, UT_EntryKey_t FuncKey, con
{
CFE_ES_AppId_t *AppIdPtr = UT_Hook_GetArgValueByName(Context, "AppIdPtr", CFE_ES_AppId_t *);
int32 status;
CFE_ES_AppId_t *IdBuff;
void * IdBuff;
size_t BuffSize;
size_t Position;

UT_Stub_GetInt32StatusCode(Context, &status);

if (status >= 0)
{
UT_GetDataBuffer(UT_KEY(CFE_ES_GetAppID), (void **)&IdBuff, &BuffSize, &Position);
UT_GetDataBuffer(UT_KEY(CFE_ES_GetAppID), &IdBuff, &BuffSize, &Position);
if (IdBuff != NULL && BuffSize == sizeof(*AppIdPtr))
{
*AppIdPtr = *IdBuff;
memcpy(AppIdPtr, IdBuff, sizeof(*AppIdPtr));
}
else
{
Expand All @@ -159,18 +159,18 @@ void UT_DefaultHandler_CFE_ES_GetTaskID(void *UserObj, UT_EntryKey_t FuncKey, co
{
CFE_ES_TaskId_t *TaskIdPtr = UT_Hook_GetArgValueByName(Context, "TaskIdPtr", CFE_ES_TaskId_t *);
int32 status;
CFE_ES_TaskId_t *IdBuff;
void * IdBuff;
size_t BuffSize;
size_t Position;

UT_Stub_GetInt32StatusCode(Context, &status);

if (status >= 0)
{
UT_GetDataBuffer(UT_KEY(CFE_ES_GetTaskID), (void **)&IdBuff, &BuffSize, &Position);
UT_GetDataBuffer(UT_KEY(CFE_ES_GetTaskID), &IdBuff, &BuffSize, &Position);
if (IdBuff != NULL && BuffSize == sizeof(*TaskIdPtr))
{
*TaskIdPtr = *IdBuff;
memcpy(TaskIdPtr, IdBuff, sizeof(*TaskIdPtr));
}
else
{
Expand All @@ -194,11 +194,11 @@ void UT_DefaultHandler_CFE_ES_GetAppIDByName(void *UserObj, UT_EntryKey_t FuncKe
CFE_ES_AppId_t *AppIdPtr = UT_Hook_GetArgValueByName(Context, "AppIdPtr", CFE_ES_AppId_t *);
const char * AppName = UT_Hook_GetArgValueByName(Context, "AppName", const char *);

size_t UserBuffSize;
size_t BuffPosition;
const char * NameBuff;
CFE_ES_AppId_t *IdBuff;
int32 status;
size_t UserBuffSize;
size_t BuffPosition;
void * NameBuff;
void * IdBuff;
int32 status;

UT_Stub_GetInt32StatusCode(Context, &status);

Expand All @@ -207,15 +207,15 @@ void UT_DefaultHandler_CFE_ES_GetAppIDByName(void *UserObj, UT_EntryKey_t FuncKe
if (UT_Stub_CopyToLocal(UT_KEY(CFE_ES_GetAppIDByName), AppIdPtr, sizeof(*AppIdPtr)) < sizeof(*AppIdPtr))
{
IdBuff = NULL;
UT_GetDataBuffer(UT_KEY(CFE_ES_GetAppName), (void **)&NameBuff, &UserBuffSize, &BuffPosition);
if (NameBuff != NULL && UserBuffSize > 0 && strncmp(NameBuff, AppName, UserBuffSize) == 0)
UT_GetDataBuffer(UT_KEY(CFE_ES_GetAppName), &NameBuff, &UserBuffSize, &BuffPosition);
if (NameBuff != NULL && UserBuffSize > 0 && strncmp((const char *)NameBuff, AppName, UserBuffSize) == 0)
{
UT_GetDataBuffer(UT_KEY(CFE_ES_GetAppID), (void **)&IdBuff, &UserBuffSize, &BuffPosition);
UT_GetDataBuffer(UT_KEY(CFE_ES_GetAppID), &IdBuff, &UserBuffSize, &BuffPosition);
}

if (IdBuff != NULL && UserBuffSize == sizeof(*AppIdPtr))
{
*AppIdPtr = *IdBuff;
memcpy(AppIdPtr, IdBuff, sizeof(*AppIdPtr));
}
else
{
Expand Down Expand Up @@ -243,18 +243,23 @@ void UT_DefaultHandler_CFE_ES_GetAppName(void *UserObj, UT_EntryKey_t FuncKey, c
size_t UserBuffSize;
size_t BuffPosition;
const char *NameBuff;
void * TempBuff;
int32 status;

UT_Stub_GetInt32StatusCode(Context, &status);

if (status >= 0 && BufferLength > 0)
{
UT_GetDataBuffer(UT_KEY(CFE_ES_GetAppName), (void **)&NameBuff, &UserBuffSize, &BuffPosition);
if (NameBuff == NULL || UserBuffSize == 0)
UT_GetDataBuffer(UT_KEY(CFE_ES_GetAppName), &TempBuff, &UserBuffSize, &BuffPosition);
if (TempBuff == NULL || UserBuffSize == 0)
{
NameBuff = "UT";
UserBuffSize = 2;
}
else
{
NameBuff = TempBuff;
}

if (UserBuffSize < BufferLength)
{
Expand Down
18 changes: 14 additions & 4 deletions modules/core_api/ut-stubs/src/cfe_fs_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void UT_DefaultHandler_CFE_FS_GetDefaultMountPoint(void *UserObj, UT_EntryKey_t
{
int32 Status;
static const char DEFAULT_MOUNTPOINT[] = "/ut";
void * TempBuff;
const char * Result;

UT_Stub_GetInt32StatusCode(Context, &Status);
Expand All @@ -58,11 +59,15 @@ void UT_DefaultHandler_CFE_FS_GetDefaultMountPoint(void *UserObj, UT_EntryKey_t
if (Status == CFE_SUCCESS)
{
/* If the test case supplied a buffer, return it, otherwise return fixed value */
UT_GetDataBuffer(UT_KEY(CFE_FS_GetDefaultMountPoint), (void **)&Result, NULL, NULL);
if (Result == NULL)
UT_GetDataBuffer(UT_KEY(CFE_FS_GetDefaultMountPoint), &TempBuff, NULL, NULL);
if (TempBuff == NULL)
{
Result = DEFAULT_MOUNTPOINT;
}
else
{
Result = TempBuff;
}
}

UT_Stub_SetReturnValue(FuncKey, Result);
Expand All @@ -77,6 +82,7 @@ void UT_DefaultHandler_CFE_FS_GetDefaultExtension(void *UserObj, UT_EntryKey_t F
{
int32 Status;
static const char DEFAULT_EXTENSION[] = ".ut";
void * TempBuff;
const char * Result;

UT_Stub_GetInt32StatusCode(Context, &Status);
Expand All @@ -85,11 +91,15 @@ void UT_DefaultHandler_CFE_FS_GetDefaultExtension(void *UserObj, UT_EntryKey_t F
if (Status == CFE_SUCCESS)
{
/* If the test case supplied a buffer, return it, otherwise return fixed value */
UT_GetDataBuffer(UT_KEY(CFE_FS_GetDefaultExtension), (void **)&Result, NULL, NULL);
if (Result == NULL)
UT_GetDataBuffer(UT_KEY(CFE_FS_GetDefaultExtension), &TempBuff, NULL, NULL);
if (TempBuff == NULL)
{
Result = DEFAULT_EXTENSION;
}
else
{
Result = TempBuff;
}
}

UT_Stub_SetReturnValue(FuncKey, Result);
Expand Down
21 changes: 13 additions & 8 deletions modules/core_api/ut-stubs/src/cfe_sb_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ typedef struct

static CFE_SB_StubMsg_MetaData_t *CFE_SB_StubMsg_GetMetaData(const CFE_MSG_Message_t *MsgPtr)
{
CFE_SB_StubMsg_MetaData_t *MetaPtr;
CFE_SB_StubMsg_MetaData_t DefaultMeta;
size_t MetaSize;
UT_EntryKey_t MsgKey = (UT_EntryKey_t)MsgPtr;
void * MetaPtr;
CFE_SB_StubMsg_MetaData_t DefaultMeta;
size_t MetaSize;
UT_EntryKey_t MsgKey = (UT_EntryKey_t)MsgPtr;

UT_GetDataBuffer(MsgKey, (void **)&MetaPtr, &MetaSize, NULL);
UT_GetDataBuffer(MsgKey, &MetaPtr, &MetaSize, NULL);
if (MetaPtr == NULL || MetaSize != sizeof(DefaultMeta))
{
memset(&DefaultMeta, 0, sizeof(DefaultMeta));
Expand All @@ -64,7 +64,7 @@ static CFE_SB_StubMsg_MetaData_t *CFE_SB_StubMsg_GetMetaData(const CFE_MSG_Messa
UT_SetDataBuffer(MsgKey, &DefaultMeta, sizeof(DefaultMeta), true);

/* Because "allocate copy" is true above, this gets a pointer to the copy */
UT_GetDataBuffer(MsgKey, (void **)&MetaPtr, &MetaSize, NULL);
UT_GetDataBuffer(MsgKey, &MetaPtr, &MetaSize, NULL);
}

return MetaPtr;
Expand Down Expand Up @@ -123,19 +123,24 @@ void UT_DefaultHandler_CFE_SB_GetPipeName(void *UserObj, UT_EntryKey_t FuncKey,

size_t UserBuffSize;
size_t BuffPosition;
void * TempBuff;
const char *NameBuff;
int32 status;

UT_Stub_GetInt32StatusCode(Context, &status);

if (status >= 0 && PipeNameSize > 0)
{
UT_GetDataBuffer(UT_KEY(CFE_SB_GetPipeName), (void **)&NameBuff, &UserBuffSize, &BuffPosition);
if (NameBuff == NULL || UserBuffSize == 0)
UT_GetDataBuffer(UT_KEY(CFE_SB_GetPipeName), &TempBuff, &UserBuffSize, &BuffPosition);
if (TempBuff == NULL || UserBuffSize == 0)
{
NameBuff = "UT";
UserBuffSize = 2;
}
else
{
NameBuff = TempBuff;
}

if (UserBuffSize < PipeNameSize)
{
Expand Down
6 changes: 4 additions & 2 deletions modules/core_private/ut-stubs/src/ut_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,13 @@ static bool UT_CheckEventHistoryFromFunc(UT_EntryKey_t Func, uint16 EventIDToSea
bool Result = false;
size_t Position;
size_t MaxSize;
void * TempBuff;
uint16 *EvBuf;

UT_GetDataBuffer(Func, (void **)&EvBuf, &MaxSize, &Position);
if (EvBuf != NULL && MaxSize > 0)
UT_GetDataBuffer(Func, &TempBuff, &MaxSize, &Position);
if (TempBuff != NULL && MaxSize > 0)
{
EvBuf = TempBuff;
Position /= sizeof(*EvBuf);
while (Position > 0)
{
Expand Down
Loading

0 comments on commit 2f4a7fd

Please sign in to comment.