When unleashing cppcheck on third party sources today of an embedded application, I encountered an issue with the use of unions in this code. The code below is an isolated, simplified example of what is happening.
Running cppcheck v2.3 on these sources: cppcheck --enable=all cppcheck_union_error.c
This yields a number of incorrect redundantAssignment warnings on the second time the wordx.u.two_shorts members of the union are written. Cppcheck seems to miss that the union members (two shorts and the 32-bit integer) overlap.
Additionally, the printf statements yield an incorrect uninitvar warning.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When unleashing cppcheck on third party sources today of an embedded application, I encountered an issue with the use of unions in this code. The code below is an isolated, simplified example of what is happening.
Program Output:
Running cppcheck v2.3 on these sources:
cppcheck --enable=all cppcheck_union_error.cThis yields a number of incorrect redundantAssignment warnings on the second time the
wordx.u.two_shortsmembers of the union are written. Cppcheck seems to miss that the union members (two shorts and the 32-bit integer) overlap.Additionally, the printf statements yield an incorrect uninitvar warning.