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 #245, #1944, Message ID type improvements #1975

Merged
merged 3 commits into from
Dec 6, 2021

Conversation

jphickey
Copy link
Contributor

Describe the contribution

  1. Makes the value for CFE_SB_MSGID_RESERVED and CFE_SB_INVALID_MSG_ID to be based on 0 rather than -1. This way, objects/values which are memset or otherwise cleared to 0 will get a safe value by default, rather than actively needing to be set to a safe value.
  2. Makes the type used for CFE_SB_MsgId_t to be a wrapper around the MsgId value, rather than a direct equivalent of the MsgId value. This increases type safety and enforces that the correct type and correct conversions (where necessary) must be employed when working with MsgIds.

Fixes #245
Fixes #1944

Testing performed
Build and sanity check CFE, run all tests

Expected behavior changes
Using "0" as a value for CFE_SB_MsgId_t no longer passes the validity test. For unit tests where values were "made up" and didn't actually need to be valid but needed to pass the CFE_SB_IsValidMsgId() test - the value 1 can be used instead of 0.

Type checking enforces that the MsgId value conversion helpers must be used when intentionally using MsgId as an int or vice versa.

System(s) tested on
Ubuntu

Contributor Info - All information REQUIRED for consideration of pull request
Joseph Hickey, Vantage Systems, Inc.

Correct code that was not correctly using the CFE_SB_ValueToMsgId or
CFE_SB_MsgIdToValue conversion wrappers where required to do so. This
should be used whenever the value is intentionally converted to/from
an integer.  The CFE_SB_MsgId_t type should not be assumed to be
an integer in nature.
Historically the CFE_SB_MSG_ID_INVALID constant was defined as 0xFFFFFFFF/-1,
where 0 was considered valid.

Although 0 is indeed valid for the first word of a CCSDS primary spacepacket header,
it is not actually valid for use with SB.  Because SB is now more decoupled from CCSDS
header definitions, there are a number of advantages to using 0 instead of -1, as
it is more passively safe:

- Objects which are cleared as part of normal BSS clearing will be set invalid
- Objects which are memset to zero will be set invalid

In contrast, when the invalid value is nonzero, objects which are memset/cleared
are valid by default, and must be actively set invalid to be safe.
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.
@skliper skliper added this to the cFS-Draco milestone Sep 24, 2021
@astrogeco astrogeco added the CCB:Approved Indicates code review and approval by community CCB label Oct 13, 2021
@astrogeco
Copy link
Contributor

CCB:2021-10-13 APPROVED

astrogeco added a commit to astrogeco/cFS that referenced this pull request Nov 17, 2021
Combines:

nasa/cFE#2001
nasa/osal#1191
nasa/PSP#318

Includes:

- nasa/cFE#1663, Use cfe time clock state enum t in cmd/tlm and handling
- nasa/cFE#1973, EVS functional test add for different event types
- nasa/cFE#1954, Patch for recursive event loop
- nasa/cFE#1911, CFE_ES_MemAddOff structure to associated CFE_ES_MemAddress_t and CFE_ES_MemOffset_t
- nasa/cFE#1986, Avoid aliasing warnings
- nasa/cFE#1975, Message ID type improvements
- nasa/cFE#1974, CFE_SB_ValueToMsgId/MsgIdToValue wrappers
- nasa/cFE#1663, Use CFE_TIME_ClockState_Enum_t in cmd/tlm and handling
- nasa/cFE#1995, Consolidate repeated MSG stub setup in sb_UT
- nasa/cFE#1873, Return type conversions in CFE_ES_GetTaskName
- nasa/cFE#1966, Better message type pointer conversion
- nasa/cFE#2002, Replacing hardcoded message limit in TIME services
- nasa/cFE#1909, Use macro in CFE_ResourceId_IsDefined
- nasa/cFE#1999, Checking against IsNewOffset only

- nasa/osal#1186, Add Duplicate Check to Local Unit Test
- nasa/osal#1178, Rename OS_XXXTime to OS_XXXLocalTime in comments
- nasa/osal#1168, Fix vxWorks intLib stub aliasing issue
- nasa/osal#1169, Recognize ifdef __cplusplus
- nasa/osal#1180, Remove extern in stub prototypes
- nasa/osal#1112, Add typedef for OSAL status codes

- nasa/PSP#301, Sleep before exit when printing
- nasa/PSP#314, Check the address in PSP get segment stubs

- nasa/elf2cfetbl#89, Check get_sh_entsize(SectionHeader) value

- nasa/cFS-GroundSystem#197, Free Address Info for Leak

- nasa/sch_lab#95, use separate address variable

- nasa/sch_lab#94, Use CFE_MSG_PTR conversion macro
- nasa/sample_app#157, Use CFE_MSG_PTR conversion macro
- nasa/ci_lab#95, Use CFE_MSG_PTR conversion macro
- nasa/to_lab#107, Use CFE_MSG_PTR conversion macro

- nasa/elf2cfetbl#93, Check get_sh_entsize(SectionHeader) value

Co-authored by: Jacob Hageman [email protected]
Co-authored by: Joseph Hickey [email protected]
Co-authored by: Ariel Adams [email protected]

Co-authored by: Paul [email protected]
Co-authored by: Zachary Gonzalez [email protected]
Co-authored by: Sam Price [email protected]
Co-authored by: Shefali Sharma [email protected]
astrogeco added a commit to astrogeco/cFS that referenced this pull request Nov 18, 2021
Combines:

nasa/cFE#2001
nasa/osal#1191
nasa/PSP#318

Includes:

- nasa/cFE#1663, Use cfe time clock state enum t in cmd/tlm and handling
- nasa/cFE#1973, EVS functional test add for different event types
- nasa/cFE#1954, Patch for recursive event loop
- nasa/cFE#1911, CFE_ES_MemAddOff structure to associated CFE_ES_MemAddress_t and CFE_ES_MemOffset_t
- nasa/cFE#1986, Avoid aliasing warnings
- nasa/cFE#1975, Message ID type improvements
- nasa/cFE#1974, CFE_SB_ValueToMsgId/MsgIdToValue wrappers
- nasa/cFE#1663, Use CFE_TIME_ClockState_Enum_t in cmd/tlm and handling
- nasa/cFE#1995, Consolidate repeated MSG stub setup in sb_UT
- nasa/cFE#1873, Return type conversions in CFE_ES_GetTaskName
- nasa/cFE#1966, Better message type pointer conversion
- nasa/cFE#2002, Replacing hardcoded message limit in TIME services
- nasa/cFE#1909, Use macro in CFE_ResourceId_IsDefined
- nasa/cFE#1999, Checking against IsNewOffset only

- nasa/osal#1186, Add Duplicate Check to Local Unit Test
- nasa/osal#1178, Rename OS_XXXTime to OS_XXXLocalTime in comments
- nasa/osal#1168, Fix vxWorks intLib stub aliasing issue
- nasa/osal#1169, Recognize ifdef __cplusplus
- nasa/osal#1180, Remove extern in stub prototypes
- nasa/osal#1112, Add typedef for OSAL status codes

- nasa/PSP#301, Sleep before exit when printing
- nasa/PSP#314, Check the address in PSP get segment stubs

- nasa/elf2cfetbl#89, Check get_sh_entsize(SectionHeader) value

- nasa/cFS-GroundSystem#197, Free Address Info for Leak

- nasa/sch_lab#95, use separate address variable

- nasa/sch_lab#94, Use CFE_MSG_PTR conversion macro
- nasa/sample_app#157, Use CFE_MSG_PTR conversion macro
- nasa/ci_lab#95, Use CFE_MSG_PTR conversion macro
- nasa/to_lab#107, Use CFE_MSG_PTR conversion macro

- nasa/elf2cfetbl#93, Check get_sh_entsize(SectionHeader) value

Co-authored by: Jacob Hageman <[email protected]>
Co-authored by: Joseph Hickey <[email protected]>
Co-authored by: Ariel Adams <[email protected]>

Co-authored by: Paul <[email protected]>
Co-authored by: Zachary Gonzalez <[email protected]>
Co-authored by: Sam Price <[email protected]>
Co-authored by: Shefali Sharma <[email protected]>
astrogeco added a commit to astrogeco/cFS that referenced this pull request Nov 18, 2021
Combines:

nasa/cFE#2001
nasa/osal#1191
nasa/PSP#318

Includes:

- nasa/cFE#1663, Use cfe time clock state enum t in cmd/tlm and handling
- nasa/cFE#1973, EVS functional test add for different event types
- nasa/cFE#1954, Patch for recursive event loop
- nasa/cFE#1911, CFE_ES_MemAddOff structure to associated CFE_ES_MemAddress_t and CFE_ES_MemOffset_t
- nasa/cFE#1986, Avoid aliasing warnings
- nasa/cFE#1975, Message ID type improvements
- nasa/cFE#1974, CFE_SB_ValueToMsgId/MsgIdToValue wrappers
- nasa/cFE#1663, Use CFE_TIME_ClockState_Enum_t in cmd/tlm and handling
- nasa/cFE#1995, Consolidate repeated MSG stub setup in sb_UT
- nasa/cFE#1873, Return type conversions in CFE_ES_GetTaskName
- nasa/cFE#1966, Better message type pointer conversion
- nasa/cFE#2002, Replacing hardcoded message limit in TIME services
- nasa/cFE#1909, Use macro in CFE_ResourceId_IsDefined
- nasa/cFE#1999, Checking against IsNewOffset only

- nasa/osal#1186, Add Duplicate Check to Local Unit Test
- nasa/osal#1178, Rename OS_XXXTime to OS_XXXLocalTime in comments
- nasa/osal#1168, Fix vxWorks intLib stub aliasing issue
- nasa/osal#1169, Recognize ifdef __cplusplus
- nasa/osal#1180, Remove extern in stub prototypes
- nasa/osal#1112, Add typedef for OSAL status codes

- nasa/PSP#301, Sleep before exit when printing
- nasa/PSP#314, Check the address in PSP get segment stubs

- nasa/elf2cfetbl#89, Check get_sh_entsize(SectionHeader) value

- nasa/cFS-GroundSystem#197, Free Address Info for Leak

- nasa/sch_lab#95, use separate address variable

- nasa/sch_lab#94, Use CFE_MSG_PTR conversion macro
- nasa/sample_app#157, Use CFE_MSG_PTR conversion macro
- nasa/ci_lab#95, Use CFE_MSG_PTR conversion macro
- nasa/to_lab#107, Use CFE_MSG_PTR conversion macro

- nasa/elf2cfetbl#93, Check get_sh_entsize(SectionHeader) value

Co-authored-by: Jacob Hageman <[email protected]>
Co-authored-by: Joseph Hickey <[email protected]>
Co-authored-by: Ariel Adams <[email protected]>
Co-authored-by: Paul <[email protected]>
Co-authored-by: Zachary Gonzalez <[email protected]>
Co-authored-by: Sam Price <[email protected]>
Co-authored-by: Shefali Sharma <[email protected]>
astrogeco added a commit to astrogeco/cFS that referenced this pull request Nov 18, 2021
Combines:

nasa/cFE#2001
nasa/osal#1191
nasa/PSP#318

Includes:

- nasa/cFE#1663, Use cfe time clock state enum t in cmd/tlm and handling
- nasa/cFE#1973, EVS functional test add for different event types
- nasa/cFE#1954, Patch for recursive event loop
- nasa/cFE#1911, CFE_ES_MemAddOff structure to associated CFE_ES_MemAddress_t and CFE_ES_MemOffset_t
- nasa/cFE#1986, Avoid aliasing warnings
- nasa/cFE#1975, Message ID type improvements
- nasa/cFE#1974, CFE_SB_ValueToMsgId/MsgIdToValue wrappers
- nasa/cFE#1663, Use CFE_TIME_ClockState_Enum_t in cmd/tlm and handling
- nasa/cFE#1995, Consolidate repeated MSG stub setup in sb_UT
- nasa/cFE#1873, Return type conversions in CFE_ES_GetTaskName
- nasa/cFE#1966, Better message type pointer conversion
- nasa/cFE#2002, Replacing hardcoded message limit in TIME services
- nasa/cFE#1909, Use macro in CFE_ResourceId_IsDefined
- nasa/cFE#1999, Checking against IsNewOffset only

- nasa/osal#1186, Add Duplicate Check to Local Unit Test
- nasa/osal#1178, Rename OS_XXXTime to OS_XXXLocalTime in comments
- nasa/osal#1168, Fix vxWorks intLib stub aliasing issue
- nasa/osal#1169, Recognize ifdef __cplusplus
- nasa/osal#1180, Remove extern in stub prototypes
- nasa/osal#1112, Add typedef for OSAL status codes

- nasa/PSP#301, Sleep before exit when printing
- nasa/PSP#314, Check the address in PSP get segment stubs

- nasa/elf2cfetbl#89, Check get_sh_entsize(SectionHeader) value

- nasa/cFS-GroundSystem#197, Free Address Info for Leak

- nasa/sch_lab#95, use separate address variable

- nasa/sch_lab#94, Use CFE_MSG_PTR conversion macro
- nasa/sample_app#157, Use CFE_MSG_PTR conversion macro
- nasa/ci_lab#95, Use CFE_MSG_PTR conversion macro
- nasa/to_lab#107, Use CFE_MSG_PTR conversion macro

- nasa/elf2cfetbl#93, Check get_sh_entsize(SectionHeader) value

Co-authored-by: Jacob Hageman <[email protected]>
Co-authored-by: Joseph Hickey <[email protected]>
Co-authored-by: Ariel Adams <[email protected]>
Co-authored-by: Paul <[email protected]>
Co-authored-by: Zachary Gonzalez <[email protected]>
Co-authored-by: Sam Price <[email protected]>
Co-authored-by: Shefali Sharma <[email protected]>
astrogeco added a commit to astrogeco/cFS that referenced this pull request Nov 18, 2021
Combines:

nasa/cFE#2001
nasa/osal#1191
nasa/PSP#318

Includes:

- nasa/cFE#1663, Use cfe time clock state enum t in cmd/tlm and handling
- nasa/cFE#1973, EVS functional test add for different event types
- nasa/cFE#1954, Patch for recursive event loop
- nasa/cFE#1911, CFE_ES_MemAddOff structure to associated CFE_ES_MemAddress_t and CFE_ES_MemOffset_t
- nasa/cFE#1986, Avoid aliasing warnings
- nasa/cFE#1975, Message ID type improvements
- nasa/cFE#1974, CFE_SB_ValueToMsgId/MsgIdToValue wrappers
- nasa/cFE#1663, Use CFE_TIME_ClockState_Enum_t in cmd/tlm and handling
- nasa/cFE#1995, Consolidate repeated MSG stub setup in sb_UT
- nasa/cFE#1873, Return type conversions in CFE_ES_GetTaskName
- nasa/cFE#1966, Better message type pointer conversion
- nasa/cFE#2002, Replacing hardcoded message limit in TIME services
- nasa/cFE#1909, Use macro in CFE_ResourceId_IsDefined
- nasa/cFE#1999, Checking against IsNewOffset only

- nasa/osal#1186, Add Duplicate Check to Local Unit Test
- nasa/osal#1178, Rename OS_XXXTime to OS_XXXLocalTime in comments
- nasa/osal#1168, Fix vxWorks intLib stub aliasing issue
- nasa/osal#1169, Recognize ifdef __cplusplus
- nasa/osal#1180, Remove extern in stub prototypes
- nasa/osal#1112, Add typedef for OSAL status codes

- nasa/PSP#301, Sleep before exit when printing
- nasa/PSP#314, Check the address in PSP get segment stubs

- nasa/elf2cfetbl#89, Check get_sh_entsize(SectionHeader) value

- nasa/cFS-GroundSystem#197, Free Address Info for Leak

- nasa/sch_lab#95, use separate address variable

- nasa/sch_lab#94, Use CFE_MSG_PTR conversion macro
- nasa/sample_app#157, Use CFE_MSG_PTR conversion macro
- nasa/ci_lab#95, Use CFE_MSG_PTR conversion macro
- nasa/to_lab#107, Use CFE_MSG_PTR conversion macro

- nasa/elf2cfetbl#93, Check get_sh_entsize(SectionHeader) value

Co-authored-by: Jacob Hageman       <[email protected]>
Co-authored-by: Joseph Hickey       <[email protected]>
Co-authored-by: Ariel Adams         <[email protected]>
Co-authored-by: Paul                <[email protected]>
Co-authored-by: Zachary Gonzalez    <[email protected]>
Co-authored-by: Sam Price           <[email protected]>
Co-authored-by: Shefali Sharma      <[email protected]>
astrogeco added a commit to nasa/cFS that referenced this pull request Nov 18, 2021
Combines:

nasa/cFE#2001
nasa/osal#1191
nasa/PSP#318

Includes:

- nasa/cFE#1663, Use cfe time clock state enum t in cmd/tlm and handling
- nasa/cFE#1973, EVS functional test add for different event types
- nasa/cFE#1954, Patch for recursive event loop
- nasa/cFE#1911, CFE_ES_MemAddOff structure to associated CFE_ES_MemAddress_t and CFE_ES_MemOffset_t
- nasa/cFE#1986, Avoid aliasing warnings
- nasa/cFE#1975, Message ID type improvements
- nasa/cFE#1974, CFE_SB_ValueToMsgId/MsgIdToValue wrappers
- nasa/cFE#1663, Use CFE_TIME_ClockState_Enum_t in cmd/tlm and handling
- nasa/cFE#1995, Consolidate repeated MSG stub setup in sb_UT
- nasa/cFE#1873, Return type conversions in CFE_ES_GetTaskName
- nasa/cFE#1966, Better message type pointer conversion
- nasa/cFE#2002, Replacing hardcoded message limit in TIME services
- nasa/cFE#1909, Use macro in CFE_ResourceId_IsDefined
- nasa/cFE#1999, Checking against IsNewOffset only

- nasa/osal#1186, Add Duplicate Check to Local Unit Test
- nasa/osal#1178, Rename OS_XXXTime to OS_XXXLocalTime in comments
- nasa/osal#1168, Fix vxWorks intLib stub aliasing issue
- nasa/osal#1169, Recognize ifdef __cplusplus
- nasa/osal#1180, Remove extern in stub prototypes
- nasa/osal#1112, Add typedef for OSAL status codes

- nasa/PSP#301, Sleep before exit when printing
- nasa/PSP#314, Check the address in PSP get segment stubs

- nasa/elf2cfetbl#89, Check get_sh_entsize(SectionHeader) value

- nasa/cFS-GroundSystem#197, Free Address Info for Leak

- nasa/sch_lab#95, use separate address variable

- nasa/sch_lab#94, Use CFE_MSG_PTR conversion macro
- nasa/sample_app#157, Use CFE_MSG_PTR conversion macro
- nasa/ci_lab#95, Use CFE_MSG_PTR conversion macro
- nasa/to_lab#107, Use CFE_MSG_PTR conversion macro

- nasa/elf2cfetbl#93, Check get_sh_entsize(SectionHeader) value

Co-authored-by: Jacob Hageman       <[email protected]>
Co-authored-by: Joseph Hickey       <[email protected]>
Co-authored-by: Ariel Adams         <[email protected]>
Co-authored-by: Paul                <[email protected]>
Co-authored-by: Zachary Gonzalez    <[email protected]>
Co-authored-by: Sam Price           <[email protected]>
Co-authored-by: Shefali Sharma      <[email protected]>
astrogeco added a commit to astrogeco/cFS that referenced this pull request Nov 18, 2021
Combines:

nasa/cFE#2001
nasa/osal#1191
nasa/PSP#318

nasa/ci_lab#101
nasa/sch_lab#102
nasa/to_lab#112
nasa/sample_app#163
nasa/cFS-GroundSystem#201
nasa/elf2cfetbl#98

Includes:

*cFE*

- nasa/cFE#1663, Use cfe time clock state enum t in cmd/tlm and handling
- nasa/cFE#1973, EVS functional test add for different event types
- nasa/cFE#1954, Patch for recursive event loop
- nasa/cFE#1911, CFE_ES_MemAddOff structure to associated CFE_ES_MemAddress_t and CFE_ES_MemOffset_t
- nasa/cFE#1986, Avoid aliasing warnings
- nasa/cFE#1975, Message ID type improvements
- nasa/cFE#1974, CFE_SB_ValueToMsgId/MsgIdToValue wrappers
- nasa/cFE#1663, Use CFE_TIME_ClockState_Enum_t in cmd/tlm and handling
- nasa/cFE#1995, Consolidate repeated MSG stub setup in sb_UT
- nasa/cFE#1873, Return type conversions in CFE_ES_GetTaskName
- nasa/cFE#1966, Better message type pointer conversion
- nasa/cFE#2002, Replacing hardcoded message limit in TIME services
- nasa/cFE#1909, Use macro in CFE_ResourceId_IsDefined
- nasa/cFE#1999, Checking against IsNewOffset only

*osal*

- nasa/osal#1186, Add Duplicate Check to Local Unit Test
- nasa/osal#1178, Rename OS_XXXTime to OS_XXXLocalTime in comments
- nasa/osal#1168, Fix vxWorks intLib stub aliasing issue
- nasa/osal#1169, Recognize ifdef __cplusplus
- nasa/osal#1180, Remove extern in stub prototypes
- nasa/osal#1112, Add typedef for OSAL status codes

*PSP*

- nasa/PSP#301, Sleep before exit when printing
- nasa/PSP#314, Check the address in PSP get segment stubs

*Tools*

- nasa/elf2cfetbl#89, Check get_sh_entsize(SectionHeader) value
- nasa/elf2cfetbl#93, Check get_sh_entsize(SectionHeader) value
- nasa/cFS-GroundSystem#197, Free Address Info for Leak

*Apps*

- nasa/sch_lab#95, use separate address variable
- nasa/sch_lab#94, Use CFE_MSG_PTR conversion macro
- nasa/sample_app#157, Use CFE_MSG_PTR conversion macro
- nasa/ci_lab#95, Use CFE_MSG_PTR conversion macro
- nasa/to_lab#107, Use CFE_MSG_PTR conversion macro

Co-authored-by: Jacob Hageman       <[email protected]>
Co-authored-by: Joseph Hickey       <[email protected]>
Co-authored-by: Ariel Adams         <[email protected]>
Co-authored-by: Paul                <[email protected]>
Co-authored-by: Zachary Gonzalez    <[email protected]>
Co-authored-by: Sam Price           <[email protected]>
Co-authored-by: Shefali Sharma      <[email protected]>
@astrogeco astrogeco merged commit 33e6a71 into nasa:main Dec 6, 2021
@jphickey jphickey deleted the fix-245-caelum-opaque-msgid branch January 18, 2022 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CCB:Approved Indicates code review and approval by community CCB draco-rc1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use 0 as CFE_SB_INVALID_MSG_ID Type safety and improved handling of CFE_SB_MsgId_t values
3 participants