I have a ton of similar issues reported by SonarQube:
m_buffer[0] = static_cast<uint32_t>(headerByte0 << 8);
Where m_buffer
is an array of uint32_t
, headerByte0
is uint8_t
. SonarQube writes:
Add an explicit cast to the result of the "<<" operator.
There is a reference to MISRA C 2004 10.5 and MISRA C++ 2008 5-0-10. Why does SonarQube not recognize the static_cast
? How to solve this?
headerByte0
touint32_t
.uint8_t
gets promoted toint
in that expression and it does not like shifts on signed integers.static_cast<uint32_t>(headerByte0) << 8