Skip to content

Commit

Permalink
Fix nasa#1965, add casts to CFE_MSG_Message_t when using SB API
Browse files Browse the repository at this point in the history
Use a cast, rather than directly referencing a member name/heirarchy
within the CFE_MSG header structures, when calling SB APIs that accept
a CFE_MSG_Message_t* type.

This cast should still have some degree of type safety, as it will
trigger an alias violation if the types are not compatible.
  • Loading branch information
jphickey committed Sep 20, 2021
1 parent 64a6a59 commit 9759e12
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 102 deletions.
18 changes: 9 additions & 9 deletions modules/es/fsw/src/cfe_es_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,19 +393,19 @@ int32 CFE_ES_TaskInit(void)
/*
** Initialize housekeeping packet (clear user data area)
*/
CFE_MSG_Init(&CFE_ES_Global.TaskData.HkPacket.TlmHeader.Msg, CFE_SB_ValueToMsgId(CFE_ES_HK_TLM_MID),
CFE_MSG_Init((CFE_MSG_Message_t*)&CFE_ES_Global.TaskData.HkPacket, CFE_SB_ValueToMsgId(CFE_ES_HK_TLM_MID),
sizeof(CFE_ES_Global.TaskData.HkPacket));

/*
** Initialize single application telemetry packet
*/
CFE_MSG_Init(&CFE_ES_Global.TaskData.OneAppPacket.TlmHeader.Msg, CFE_SB_ValueToMsgId(CFE_ES_APP_TLM_MID),
CFE_MSG_Init((CFE_MSG_Message_t*)&CFE_ES_Global.TaskData.OneAppPacket, CFE_SB_ValueToMsgId(CFE_ES_APP_TLM_MID),
sizeof(CFE_ES_Global.TaskData.OneAppPacket));

/*
** Initialize memory pool statistics telemetry packet
*/
CFE_MSG_Init(&CFE_ES_Global.TaskData.MemStatsPacket.TlmHeader.Msg, CFE_SB_ValueToMsgId(CFE_ES_MEMSTATS_TLM_MID),
CFE_MSG_Init((CFE_MSG_Message_t*)&CFE_ES_Global.TaskData.MemStatsPacket, CFE_SB_ValueToMsgId(CFE_ES_MEMSTATS_TLM_MID),
sizeof(CFE_ES_Global.TaskData.MemStatsPacket));

/*
Expand Down Expand Up @@ -839,8 +839,8 @@ int32 CFE_ES_HousekeepingCmd(const CFE_MSG_CommandHeader_t *data)
/*
** Send housekeeping telemetry packet.
*/
CFE_SB_TimeStampMsg(&CFE_ES_Global.TaskData.HkPacket.TlmHeader.Msg);
CFE_SB_TransmitMsg(&CFE_ES_Global.TaskData.HkPacket.TlmHeader.Msg, true);
CFE_SB_TimeStampMsg((CFE_MSG_Message_t*)&CFE_ES_Global.TaskData.HkPacket);
CFE_SB_TransmitMsg((CFE_MSG_Message_t*)&CFE_ES_Global.TaskData.HkPacket, true);

/*
** This command does not affect the command execution counter.
Expand Down Expand Up @@ -1235,8 +1235,8 @@ int32 CFE_ES_QueryOneCmd(const CFE_ES_QueryOneCmd_t *data)
/*
** Send application status telemetry packet.
*/
CFE_SB_TimeStampMsg(&CFE_ES_Global.TaskData.OneAppPacket.TlmHeader.Msg);
Result = CFE_SB_TransmitMsg(&CFE_ES_Global.TaskData.OneAppPacket.TlmHeader.Msg, true);
CFE_SB_TimeStampMsg((CFE_MSG_Message_t*)&CFE_ES_Global.TaskData.OneAppPacket);
Result = CFE_SB_TransmitMsg((CFE_MSG_Message_t*)&CFE_ES_Global.TaskData.OneAppPacket, true);
if (Result == CFE_SUCCESS)
{
CFE_ES_Global.TaskData.CommandCounter++;
Expand Down Expand Up @@ -1974,8 +1974,8 @@ int32 CFE_ES_SendMemPoolStatsCmd(const CFE_ES_SendMemPoolStatsCmd_t *data)
/*
** Send memory statistics telemetry packet.
*/
CFE_SB_TimeStampMsg(&CFE_ES_Global.TaskData.MemStatsPacket.TlmHeader.Msg);
CFE_SB_TransmitMsg(&CFE_ES_Global.TaskData.MemStatsPacket.TlmHeader.Msg, true);
CFE_SB_TimeStampMsg((CFE_MSG_Message_t*)&CFE_ES_Global.TaskData.MemStatsPacket);
CFE_SB_TransmitMsg((CFE_MSG_Message_t*)&CFE_ES_Global.TaskData.MemStatsPacket, true);

CFE_ES_Global.TaskData.CommandCounter++;
CFE_EVS_SendEvent(CFE_ES_TLM_POOL_STATS_INFO_EID, CFE_EVS_EventType_DEBUG,
Expand Down
1 change: 1 addition & 0 deletions modules/es/fsw/src/cfe_es_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "cfe_fs_api_typedefs.h"
#include "cfe_sb_api_typedefs.h"
#include "cfe_es_erlog_typedef.h"
#include "cfe_msg_api_typedefs.h"

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

Expand Down
2 changes: 1 addition & 1 deletion modules/es/ut-coverage/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,7 @@ void TestTask(void)
union
{
CFE_MSG_Message_t Msg;
CFE_ES_NoArgsCmd_t NoArgsCmd;
CFE_MSG_CommandHeader_t NoArgsCmd;
CFE_ES_ClearSysLogCmd_t ClearSysLogCmd;
CFE_ES_ClearERLogCmd_t ClearERLogCmd;
CFE_ES_ResetPRCountCmd_t ResetPRCountCmd;
Expand Down
6 changes: 3 additions & 3 deletions modules/evs/fsw/src/cfe_evs_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int32 CFE_EVS_EarlyInit(void)
memset(&CFE_EVS_Global, 0, sizeof(CFE_EVS_Global));

/* Initialize housekeeping packet */
CFE_MSG_Init(&CFE_EVS_Global.EVS_TlmPkt.TlmHeader.Msg, CFE_SB_ValueToMsgId(CFE_EVS_HK_TLM_MID),
CFE_MSG_Init((CFE_MSG_Message_t*)&CFE_EVS_Global.EVS_TlmPkt, CFE_SB_ValueToMsgId(CFE_EVS_HK_TLM_MID),
sizeof(CFE_EVS_Global.EVS_TlmPkt));

/* Elements stored in the hk packet that have non-zero default values */
Expand Down Expand Up @@ -672,9 +672,9 @@ int32 CFE_EVS_ReportHousekeepingCmd(const CFE_MSG_CommandHeader_t *data)
AppTlmDataPtr->AppMessageSentCounter = 0;
}

CFE_SB_TimeStampMsg(&CFE_EVS_Global.EVS_TlmPkt.TlmHeader.Msg);
CFE_SB_TimeStampMsg((CFE_MSG_Message_t*)&CFE_EVS_Global.EVS_TlmPkt);

CFE_SB_TransmitMsg(&CFE_EVS_Global.EVS_TlmPkt.TlmHeader.Msg, true);
CFE_SB_TransmitMsg((CFE_MSG_Message_t*)&CFE_EVS_Global.EVS_TlmPkt, true);

return CFE_STATUS_NO_COUNTER_INCREMENT;
}
Expand Down
12 changes: 6 additions & 6 deletions modules/evs/fsw/src/cfe_evs_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void EVS_GenerateEventTelemetry(EVS_AppData_t *AppDataPtr, uint16 EventID, uint1
int ExpandedLength;

/* Initialize EVS event packets */
CFE_MSG_Init(&LongEventTlm.TlmHeader.Msg, CFE_SB_ValueToMsgId(CFE_EVS_LONG_EVENT_MSG_MID), sizeof(LongEventTlm));
CFE_MSG_Init((CFE_MSG_Message_t*)&LongEventTlm, CFE_SB_ValueToMsgId(CFE_EVS_LONG_EVENT_MSG_MID), sizeof(LongEventTlm));
LongEventTlm.Payload.PacketID.EventID = EventID;
LongEventTlm.Payload.PacketID.EventType = EventType;

Expand All @@ -388,7 +388,7 @@ void EVS_GenerateEventTelemetry(EVS_AppData_t *AppDataPtr, uint16 EventID, uint1
LongEventTlm.Payload.PacketID.ProcessorID = CFE_PSP_GetProcessorId();

/* Set the packet timestamp */
CFE_MSG_SetMsgTime(&LongEventTlm.TlmHeader.Msg, *TimeStamp);
CFE_MSG_SetMsgTime((CFE_MSG_Message_t*)&LongEventTlm, *TimeStamp);

/* Write event to the event log */
EVS_AddLog(&LongEventTlm);
Expand All @@ -399,7 +399,7 @@ void EVS_GenerateEventTelemetry(EVS_AppData_t *AppDataPtr, uint16 EventID, uint1
if (CFE_EVS_Global.EVS_TlmPkt.Payload.MessageFormatMode == CFE_EVS_MsgFormat_LONG)
{
/* Send long event via SoftwareBus */
CFE_SB_TransmitMsg(&LongEventTlm.TlmHeader.Msg, true);
CFE_SB_TransmitMsg((CFE_MSG_Message_t*)&LongEventTlm, true);
}
else if (CFE_EVS_Global.EVS_TlmPkt.Payload.MessageFormatMode == CFE_EVS_MsgFormat_SHORT)
{
Expand All @@ -409,11 +409,11 @@ void EVS_GenerateEventTelemetry(EVS_AppData_t *AppDataPtr, uint16 EventID, uint1
*
* This goes out on a separate message ID.
*/
CFE_MSG_Init(&ShortEventTlm.TlmHeader.Msg, CFE_SB_ValueToMsgId(CFE_EVS_SHORT_EVENT_MSG_MID),
CFE_MSG_Init((CFE_MSG_Message_t*)&ShortEventTlm, CFE_SB_ValueToMsgId(CFE_EVS_SHORT_EVENT_MSG_MID),
sizeof(ShortEventTlm));
CFE_MSG_SetMsgTime(&ShortEventTlm.TlmHeader.Msg, *TimeStamp);
CFE_MSG_SetMsgTime((CFE_MSG_Message_t*)&ShortEventTlm, *TimeStamp);
ShortEventTlm.Payload.PacketID = LongEventTlm.Payload.PacketID;
CFE_SB_TransmitMsg(&ShortEventTlm.TlmHeader.Msg, true);
CFE_SB_TransmitMsg((CFE_MSG_Message_t*)&ShortEventTlm, true);
}

/* Increment message send counters (prevent rollover) */
Expand Down
8 changes: 4 additions & 4 deletions modules/evs/ut-coverage/evs_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ void Test_Logging(void)
char tmpString[100];
union
{
CFE_EVS_NoArgsCmd_t cmd;
CFE_MSG_CommandHeader_t cmd;
CFE_EVS_SetLogModeCmd_t modecmd;
CFE_EVS_WriteLogDataFileCmd_t logfilecmd;
} CmdBuf;
Expand Down Expand Up @@ -1003,7 +1003,7 @@ void Test_WriteApp(void)
{
union
{
CFE_EVS_NoArgsCmd_t cmd;
CFE_MSG_CommandHeader_t cmd;
CFE_EVS_WriteAppDataFileCmd_t AppDataCmd;
CFE_EVS_AppNameBitMaskCmd_t appbitcmd;
} CmdBuf;
Expand Down Expand Up @@ -1683,7 +1683,7 @@ void Test_FilterCmd(void)
*/
void Test_InvalidCmd(void)
{
CFE_EVS_NoArgsCmd_t cmd;
CFE_MSG_CommandHeader_t cmd;

UtPrintf("Begin Test Invalid Command");

Expand Down Expand Up @@ -1816,7 +1816,7 @@ void Test_Misc(void)
union
{
CFE_MSG_Message_t msg;
CFE_EVS_NoArgsCmd_t cmd;
CFE_MSG_CommandHeader_t cmd;
CFE_EVS_SetLogModeCmd_t modecmd;
CFE_EVS_WriteLogDataFileCmd_t writelogdatacmd;
} PktBuf;
Expand Down
2 changes: 1 addition & 1 deletion modules/sb/fsw/src/cfe_sb_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int32 CFE_SB_EarlyInit(void)
CFE_SBR_Init();

/* Initialize the SB Statistics Pkt */
CFE_MSG_Init(&CFE_SB_Global.StatTlmMsg.Hdr.Msg, CFE_SB_ValueToMsgId(CFE_SB_STATS_TLM_MID),
CFE_MSG_Init((CFE_MSG_Message_t*)&CFE_SB_Global.StatTlmMsg, CFE_SB_ValueToMsgId(CFE_SB_STATS_TLM_MID),
sizeof(CFE_SB_Global.StatTlmMsg));

return Stat;
Expand Down
20 changes: 10 additions & 10 deletions modules/sb/fsw/src/cfe_sb_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ int32 CFE_SB_AppInit(void)

CFE_ES_WriteToSysLog("%s: Registered %d events for filtering\n", __func__, (int)CfgFileEventsToFilter);

CFE_MSG_Init(&CFE_SB_Global.HKTlmMsg.Hdr.Msg, CFE_SB_ValueToMsgId(CFE_SB_HK_TLM_MID),
CFE_MSG_Init((CFE_MSG_Message_t*)&CFE_SB_Global.HKTlmMsg, CFE_SB_ValueToMsgId(CFE_SB_HK_TLM_MID),
sizeof(CFE_SB_Global.HKTlmMsg));

CFE_MSG_Init(&CFE_SB_Global.PrevSubMsg.Hdr.Msg, CFE_SB_ValueToMsgId(CFE_SB_ALLSUBS_TLM_MID),
CFE_MSG_Init((CFE_MSG_Message_t*)&CFE_SB_Global.PrevSubMsg, CFE_SB_ValueToMsgId(CFE_SB_ALLSUBS_TLM_MID),
sizeof(CFE_SB_Global.PrevSubMsg));

/* Populate the fixed fields in the HK Tlm Msg */
Expand Down Expand Up @@ -535,8 +535,8 @@ int32 CFE_SB_SendHKTlmCmd(const CFE_MSG_CommandHeader_t *data)

CFE_SB_UnlockSharedData(__FILE__, __LINE__);

CFE_SB_TimeStampMsg(&CFE_SB_Global.HKTlmMsg.Hdr.Msg);
CFE_SB_TransmitMsg(&CFE_SB_Global.HKTlmMsg.Hdr.Msg, true);
CFE_SB_TimeStampMsg((CFE_MSG_Message_t*)&CFE_SB_Global.HKTlmMsg);
CFE_SB_TransmitMsg((CFE_MSG_Message_t*)&CFE_SB_Global.HKTlmMsg, true);

return CFE_SUCCESS;
}
Expand Down Expand Up @@ -757,8 +757,8 @@ int32 CFE_SB_SendStatsCmd(const CFE_SB_SendSbStatsCmd_t *data)
--PipeStatCount;
}

CFE_SB_TimeStampMsg(&CFE_SB_Global.StatTlmMsg.Hdr.Msg);
CFE_SB_TransmitMsg(&CFE_SB_Global.StatTlmMsg.Hdr.Msg, true);
CFE_SB_TimeStampMsg((CFE_MSG_Message_t*)&CFE_SB_Global.StatTlmMsg);
CFE_SB_TransmitMsg((CFE_MSG_Message_t*)&CFE_SB_Global.StatTlmMsg, true);

CFE_EVS_SendEvent(CFE_SB_SND_STATS_EID, CFE_EVS_EventType_DEBUG, "Software Bus Statistics packet sent");

Expand Down Expand Up @@ -865,14 +865,14 @@ int32 CFE_SB_SendSubscriptionReport(CFE_SB_MsgId_t MsgId, CFE_SB_PipeId_t PipeId

if (CFE_SB_Global.SubscriptionReporting == CFE_SB_ENABLE)
{
CFE_MSG_Init(&SubRptMsg.Hdr.Msg, CFE_SB_ValueToMsgId(CFE_SB_ONESUB_TLM_MID), sizeof(SubRptMsg));
CFE_MSG_Init((CFE_MSG_Message_t*)&SubRptMsg, CFE_SB_ValueToMsgId(CFE_SB_ONESUB_TLM_MID), sizeof(SubRptMsg));

SubRptMsg.Payload.MsgId = MsgId;
SubRptMsg.Payload.Pipe = PipeId;
SubRptMsg.Payload.Qos = Quality;
SubRptMsg.Payload.SubType = CFE_SB_SUBSCRIPTION;

Status = CFE_SB_TransmitMsg(&SubRptMsg.Hdr.Msg, true);
Status = CFE_SB_TransmitMsg((CFE_MSG_Message_t*)&SubRptMsg, true);
CFE_EVS_SendEventWithAppID(CFE_SB_SUBSCRIPTION_RPT_EID, CFE_EVS_EventType_DEBUG, CFE_SB_Global.AppId,
"Sending Subscription Report Msg=0x%x,Pipe=%lu,Stat=0x%x",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), CFE_RESOURCEID_TO_ULONG(PipeId),
Expand Down Expand Up @@ -1334,7 +1334,7 @@ void CFE_SB_SendRouteSub(CFE_SBR_RouteId_t RouteId, void *ArgPtr)
if (CFE_SB_Global.PrevSubMsg.Payload.Entries >= CFE_SB_SUB_ENTRIES_PER_PKT)
{
CFE_SB_UnlockSharedData(__func__, __LINE__);
status = CFE_SB_TransmitMsg(&CFE_SB_Global.PrevSubMsg.Hdr.Msg, true);
status = CFE_SB_TransmitMsg((CFE_MSG_Message_t*)&CFE_SB_Global.PrevSubMsg, true);
CFE_EVS_SendEvent(CFE_SB_FULL_SUB_PKT_EID, CFE_EVS_EventType_DEBUG,
"Full Sub Pkt %d Sent,Entries=%d,Stat=0x%x\n",
(int)CFE_SB_Global.PrevSubMsg.Payload.PktSegment,
Expand Down Expand Up @@ -1385,7 +1385,7 @@ int32 CFE_SB_SendPrevSubsCmd(const CFE_SB_SendPrevSubsCmd_t *data)
/* if pkt has any number of entries, send it as a partial pkt */
if (CFE_SB_Global.PrevSubMsg.Payload.Entries > 0)
{
status = CFE_SB_TransmitMsg(&CFE_SB_Global.PrevSubMsg.Hdr.Msg, true);
status = CFE_SB_TransmitMsg((CFE_MSG_Message_t*)&CFE_SB_Global.PrevSubMsg, true);
CFE_EVS_SendEvent(CFE_SB_PART_SUB_PKT_EID, CFE_EVS_EventType_DEBUG,
"Partial Sub Pkt %d Sent,Entries=%d,Stat=0x%x",
(int)CFE_SB_Global.PrevSubMsg.Payload.PktSegment,
Expand Down
2 changes: 1 addition & 1 deletion modules/sb/fsw/src/cfe_sb_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ size_t CFE_SB_MsgHdrSize(const CFE_MSG_Message_t *MsgPtr)
/* Since all cFE messages must have a secondary hdr this check is not needed */
if (!hassechdr)
{
size = sizeof(CCSDS_SpacePacket_t);
size = sizeof(CFE_MSG_Message_t);
}
else if (type == CFE_MSG_Type_Cmd)
{
Expand Down
Loading

0 comments on commit 9759e12

Please sign in to comment.