nasa / LC

The Core Flight System (cFS) Limit Checker (LC) application.
Apache License 2.0
30 stars 21 forks source link

Improper use of unions in LC_GetSizedWPData #72

Closed jphickey closed 1 year ago

jphickey commented 1 year ago

Checklist (Please check before submitting)

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.

Code snips This writes to Unsigned8 but then reads from Signed8: https://github.com/nasa/LC/blob/f49a965a329dd853bd2fdd9ad3c0137d736154a0/fsw/src/lc_watch.c#L854-L855

Additionally, Many cases write to Signed32 but only Unsigned32 is read here at the end: https://github.com/nasa/LC/blob/f49a965a329dd853bd2fdd9ad3c0137d736154a0/fsw/src/lc_watch.c#L922

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