Skip to content

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

@jphickey

Description

@jphickey

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*.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions