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

CF command tests need to use union when instantiating objects of type CFE_SB_Buffer_t #49

Closed
jphickey opened this issue Nov 23, 2021 · 0 comments · Fixed by #79
Closed
Milestone

Comments

@jphickey
Copy link
Contributor

This issue was imported from the GSFC issue tracking system

Imported from: [GSFCCFS-1785] CF command tests need to use union when instantiating objects of type CFE_SB_Buffer_t
Originally submitted by: Hickey, Joseph P. (GSFC-582.0)[VANTAGE SYSTEMS INC] on Tue Nov 16 17:29:44 2021

Original Description:
This is similar in nature to previous issue described in #44 but in the "cf_cmd_tests.c" file.

In this instance, command buffers are instantiated on the stack, but then cast to CFE_SB_Buffer_t*. The stack variables are not correctly aligned for this cast to be valid, and many compilers will (correctly) trigger a warning/error about this.

Solution is to use a union to ensure alignment, where code like:

    cf_cmd_unionargs_t dummy_msg;
    CFE_SB_Buffer_t* arg_msg = (CFE_SB_Buffer_t*)&dummy_msg;

Needs to become:

    union
    {
        cf_cmd_unionargs_t msg;
        CFE_SB_Buffer_t buf;
    } dummy;

such that &dummy.buf can serve as the pointer to pass to a function accepting a CFE_SB_Buffer_t*.

jphickey added a commit to jphickey/CF that referenced this issue Nov 23, 2021
Where ever a unit test is generating a buffer on the stack to send to a
command processing function, this typically needs to be represented as
a CFE_SB_Buffer_t* pointer, which by definition is supposed to be
aligned to the worst-possible case, which may be greater than the
alignment requirement of the actual command type.

To avoid warnings when converting between types, use a union to ensure
the stack object meets the alignment requirements for CFE_SB_Buffer_t.

Furthermore, ensure all buffers instantiated on the stack are cleared
(memset to 0) before operating on them or passing them to a CF function.
jphickey added a commit to jphickey/CF that referenced this issue Dec 1, 2021
Where ever a unit test is generating a buffer on the stack to send to a
command processing function, this typically needs to be represented as
a CFE_SB_Buffer_t* pointer, which by definition is supposed to be
aligned to the worst-possible case, which may be greater than the
alignment requirement of the actual command type.

To avoid warnings when converting between types, use a union to ensure
the stack object meets the alignment requirements for CFE_SB_Buffer_t.

Furthermore, ensure all buffers instantiated on the stack are cleared
(memset to 0) before operating on them or passing them to a CF function.
astrogeco added a commit that referenced this issue Dec 8, 2021
Fix #49, aligned buffer for all test commands
@skliper skliper added this to the Draco milestone Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants