[x] I performed a cursory search to see if the bug report is relevant, not redundant, nor in conflict with other tickets.
Describe the bug
The LC_GetSizedWPData function is not using the LC_MultiType_t union properly. It is writing to one member and then reading from another, different member of the same union. This is "type punning" and may not work in an optimized build.
The new version of CppCheck reports this issue.
To Reproduce
Run Cppcheck workflow to see issue.
No known way to actually produce a failure though, as most platforms will behave as the code expects it to, its just not guaranteed to work.
Expected behavior
Should not read from a different union member than was written to.
Additional context
This code does work as intended but is not necessarily safe/portable across platforms in its current form, particularly when optimization is enabled.
Reporter Info
Joseph Hickey, Vantage Systems, Inc.
Checklist (Please check before submitting)
Describe the bug The
LC_GetSizedWPData
function is not using theLC_MultiType_t
union properly. It is writing to one member and then reading from another, different member of the same union. This is "type punning" and may not work in an optimized build.The new version of CppCheck reports this issue.
To Reproduce Run Cppcheck workflow to see issue. No known way to actually produce a failure though, as most platforms will behave as the code expects it to, its just not guaranteed to work.
Expected behavior Should not read from a different union member than was written to.
Code snips This writes to
Unsigned8
but then reads fromSigned8
: https://github.com/nasa/LC/blob/f49a965a329dd853bd2fdd9ad3c0137d736154a0/fsw/src/lc_watch.c#L854-L855Additionally, Many cases write to
Signed32
but onlyUnsigned32
is read here at the end: https://github.com/nasa/LC/blob/f49a965a329dd853bd2fdd9ad3c0137d736154a0/fsw/src/lc_watch.c#L922System observed on: N/A
Additional context This code does work as intended but is not necessarily safe/portable across platforms in its current form, particularly when optimization is enabled.
Reporter Info Joseph Hickey, Vantage Systems, Inc.