Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mohammedRafeeque opened this issue May 9, 2024 · 7 comments
Assignees
Labels
bug Something isn't working c++ C++ language generator wontfix This will not be worked on
Milestone

Comments

@mohammedRafeeque
Copy link

mohammedRafeeque commented May 9, 2024

Zserio version and language
Zserio: master branch
Commit hash: 4d22803
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 mohammedRafeeque added the bug Something isn't working label May 9, 2024
@mohammedRafeeque
Copy link
Author

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

@mikir
Copy link
Contributor

mikir commented May 10, 2024

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 mikir added the c++ C++ language generator label May 10, 2024
@mikir mikir added this to the 2.15 milestone May 10, 2024
@mikir mikir changed the title Fix MISRA C++ 2023 rule 7.0.5 1"Integral promotion or the usual arithmetic conversions shall not change the type signedness" Fix MISRA C++ 2023 rule 7.0.5 "Integral promotion or the usual arithmetic conversions shall not change the type signedness" May 14, 2024
@mikir
Copy link
Contributor

mikir commented May 24, 2024

@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 mikir self-assigned this May 24, 2024
@mohammedRafeeque
Copy link
Author

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
Copy link
Author

zserio_modifiedfiles_FileUtil_and_BitStreamWriter.zip

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

@mikir
Copy link
Contributor

mikir commented Jun 5, 2024

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 Mi-La added the wontfix This will not be worked on label Aug 2, 2024
@Mi-La
Copy link
Contributor

Mi-La commented Aug 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working c++ C++ language generator wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants