ndsev / zserio

zero sugar, zero fat, zero serialization overhead
https://zserio.org/
BSD 3-Clause "New" or "Revised" License
109 stars 27 forks source link

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

Closed mohammedRafeeque closed 1 month ago

mohammedRafeeque commented 4 months ago

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 commented 4 months ago

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

mikir commented 4 months ago

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 commented 4 months ago

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

mohammedRafeeque commented 4 months ago

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(exponent16 << FLOAT16_EXPONENT_BIT_POSITION);

mohammedRafeeque commented 4 months ago

zserio_modifiedfiles_FileUtil_and_BitStreamWriter.zip

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

mikir commented 4 months ago

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.

Mi-La commented 2 months ago

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