You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
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*.
The text was updated successfully, but these errors were encountered: