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.11.2 "An array passed as a function argument shall not decay to a pointer" #660

Closed
mikir opened this issue Aug 22, 2024 · 1 comment
Assignees
Labels
bug Something isn't working c++ C++ language generator
Milestone

Comments

@mikir
Copy link
Contributor

mikir commented Aug 22, 2024

There is a corresponding SonarCloud rule S945 which is able to catch some problems in the C++ runtime library. For example in CppRuntimeException.h:

return exception << "vector([...], " << value.size() << ")";

The problem in the previous example is that the string literal "vector([...])," is silently casted from the const char[N] to the const char*.

Enable this rule and fix all found issues.

@mikir mikir added bug Something isn't working c++ C++ language generator labels Aug 22, 2024
@mikir mikir added this to the 2.15 milestone Aug 22, 2024
@Mi-La
Copy link
Contributor

Mi-La commented Aug 23, 2024

We need support for const char* overload to keep convenient usage of CppRuntimeException. The exception is thrown only from Zserio controlled code and we can ensure that all strings are properly zero-terminated.

Note that it's not trivial to add an overload for const char (&message)[N] since the overload resolution would still choose const char* overload.
Also we have use-cases where we currently need to support const char* - e.g. exception throw by zserio enums. It could be possible to change it, but it would be significant amount of work.

Currently we have resolved 3 issues in SonarCoud.

@Mi-La Mi-La closed this as completed Sep 2, 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