Skip to content

Commit

Permalink
Fix nasa#245, use type safe value for CFE_SB_MsgId_t
Browse files Browse the repository at this point in the history
This makes CFE_SB_MsgId_t to be a safe wrapper around CFE_SB_MsgId_Atom_t,
such that the values cannot be silently/implicitly interchanged with other
integers.

This enforces that the MsgId/Value conversion helpers must be used when
conversion to/from integers is intended.
  • Loading branch information
jphickey committed Sep 23, 2021
1 parent 7320f2f commit 6cf6d4c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions modules/core_api/fsw/inc/cfe_sb_api_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@
*
* \sa CFE_SB_ValueToMsgId()
*/
#define CFE_SB_MSGID_WRAP_VALUE(val) (val)
#define CFE_SB_MSGID_WRAP_VALUE(val) \
{ \
val \
}

/**
* \brief Translation macro to convert to MsgId integer values from a literal
Expand All @@ -88,7 +91,7 @@
*
* \sa CFE_SB_MsgIdToValue()
*/
#define CFE_SB_MSGID_UNWRAP_VALUE(mid) ((CFE_SB_MsgId_Atom_t)(mid))
#define CFE_SB_MSGID_UNWRAP_VALUE(mid) ((mid).Value)

/**
* \brief Reserved value for CFE_SB_MsgId_t that will not match any valid MsgId
Expand Down
5 changes: 4 additions & 1 deletion modules/core_api/fsw/inc/cfe_sb_extern_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ typedef uint32 CFE_SB_MsgId_Atom_t;
* @note In a future version it could become a type-safe wrapper similar to the route index,
* to avoid message IDs getting mixed between other integer values.
*/
typedef CFE_SB_MsgId_Atom_t CFE_SB_MsgId_t;
typedef struct
{
CFE_SB_MsgId_Atom_t Value;
} CFE_SB_MsgId_t;

/** \brief CFE_SB_PipeId_t to primitive type definition
*
Expand Down

0 comments on commit 6cf6d4c

Please sign in to comment.