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 0.1.2 "The value returned by a function shall be used" #607

Closed
mohammedRafeeque opened this issue May 9, 2024 · 2 comments
Assignees
Labels
bug Something isn't working c++ C++ language generator
Milestone

Comments

@mohammedRafeeque
Copy link

Zserio version and language
Zserio: master branch
Commit hash: 4d22803
Language: C++
Priority : 3

Describe the bug
Check and resolve SCA warning MISRACPP2023-0_1_2-a " Unused function's 'put' return value"

See the attached xls for the SCA warning details
MISRACPP2023-0_1_2-a_Warning_ZserioRuntime.xlsx

How to reproduce
Steps to reproduce the behavior:
SCA run using MISRA 2023 configuration.

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
@mikir
Copy link
Contributor

mikir commented May 10, 2024

Probably SonarCloud rule 'The value returned by a function shall be "used"' 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 MISRACPP2023-0_1_2-a " Unused function's 'put' return value" Fix MISRA C++ 2023 rule MISRACPP2023-0_1_2 "Unused function's 'put' return value" May 14, 2024
@mikir mikir changed the title Fix MISRA C++ 2023 rule MISRACPP2023-0_1_2 "Unused function's 'put' return value" Fix MISRA C++ 2023 rule 0.1.2 "Unused function's 'put' return value" May 14, 2024
@mikir mikir self-assigned this May 24, 2024
@mikir mikir changed the title Fix MISRA C++ 2023 rule 0.1.2 "Unused function's 'put' return value" Fix MISRA C++ 2023 rule 0.1.2 "The value returned by a function shall be used" May 24, 2024
mikir added a commit that referenced this issue May 27, 2024
@mikir
Copy link
Contributor

mikir commented May 30, 2024

We went through all reported functions where the returned value should be checked. We have added explicit check of returned value wherever it makes sense.

However, there are still some cases where the check does not make sense (e.g. if function returns *this to allow subsequent calls). The following list contains all SonarCloud issues which have been accepted as the exceptions:

Module Line Command Link
BitStreamReader.h 334 std::copy(sourceIt, sourceIt + numBytesToRead, buffer.begin()); SonarCloud
BitStreamWriter.cpp 488 std::copy(data.begin(), data.end(), m_buffer.begin() + beginBitPosition / 8); SonarCloud
BitStreamWriter.cpp 513 std::copy(data.begin(), data.begin() + len, m_buffer.data() + beginBitPosition / 8); SonarCloud
BitStreamWriter.h 260 std::copy(buffer.begin(), buffer.begin() + numBytesToWrite, m_buffer.data() + beginBitPosition / 8); SonarCloud
CppRuntimeException.cpp 39 std::copy(message.begin(), message.end(), m_buffer.begin() + m_len); SonarCloud
FileUtil.cpp 33 stream.seekg(0, stream.end); SonarCloud
FileUtil.cpp 35 stream.seekg(0); SonarCloud
JsonEncoder.cpp 54 + 9x stream.put('"'); SonarCloud

There are no exceptions in the generated code.

@mikir mikir closed this as completed May 30, 2024
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
Projects
None yet
Development

No branches or pull requests

2 participants