zserio icon indicating copy to clipboard operation
zserio copied to clipboard

Fix MISRA C++ 2023 rule 7.0.5 "Integral promotion or the usual arithmetic conversions shall not change the type signedness"

Open mohammedRafeeque opened this issue 1 year ago • 6 comments

Zserio version and language Zserio: master branch Commit hash: 4d228036f4cb51199e151292968c8ecacc4924ce Language: C++ Priority : 1

Describe the bug Check and resolve SCA warning MISRACPP2023-7_0_5-a Integral promotion or the usual arithmetic conversions shall not change the type signedness of an operand from 'uint16_t' to 'int'

How to reproduce Steps to reproduce the behavior: SCA run usinf MISRA 2023 configuration. See the attached excel for 251 warnings details and location reference.

Expected behavior No SCA warnings for MISRA 2023 ruleset

Additional context N.A

@Roland-Homeier @mikir FYI.

mohammedRafeeque avatar May 09 '24 10:05 mohammedRafeeque

MISRACPP2023-7_0_5-a_Warning_ZserioRuntime.xlsx Warnings report attached.

mohammedRafeeque avatar May 09 '24 10:05 mohammedRafeeque

Probably SonarCloud rule "Signed and unsigned types should not be mixed in expressions" could be used for this. We will investigate it during the current milestone.

mikir avatar May 10 '24 08:05 mikir

@mohammedRafeeque, we have tried to use the SonarCloud rule "Signed and unsigned types should not be mixed in expressions". Unfortunatelly, this rule does not catch anything from given xlsx sheet. So, we should discuss how to continue with the rule which we are not able to reproduce.

Besides of that, please check the attached xlsx. For example, there is a finding in FloatUtil.cpp, line 158 (2 times). However, this line is a comment. Please check it here.

mikir avatar May 24 '24 07:05 mikir

You are right in FloatUtil.cpp and BitStreamWriter.cpp there is a auto formating done in local version. So there is a change in line number to mentioned tag version. Line 158 refers to source code line below const uint16_t exponent16Shifted = static_cast<uint16_t>(exponent16 << FLOAT16_EXPONENT_BIT_POSITION);

mohammedRafeeque avatar May 24 '24 12:05 mohammedRafeeque

zserio_modifiedfiles_FileUtil_and_BitStreamWriter.zip

Refer the attached zip file for locally modified version of two files FloatUtil.cpp and BitStreamWriter.cpp

mohammedRafeeque avatar May 24 '24 12:05 mohammedRafeeque

Unfortunately, the corresponding SonarCloud rule did not catch anything (clang-tidy and compiler warnings did not catch anything as well). We are not able to reproduce it and we are not going to fix it blindly.

mikir avatar Jun 05 '24 14:06 mikir

Enabled also Sonar Rule cpp:S5276 - Implicit casts should not lower precision, nothing caught.

Mi-La avatar Aug 02 '24 09:08 Mi-La