Hi,
In a large project I have a macro which CppCheck 2.3 does not know about. The result of this is that CppCheck in this case does not detect a CWE 762 “Mismatching allocation and deallocation” error.
Below sample code can reproduce the error. When CWE_762 is undefined no 762 error is reported.
If I include the #define or remove the “CWE_762("test");” the error is detected correctly.
Thanks! It seems that Cppcheck bails out, I am not sure if there is some good reasons for that or not. I created ticket https://trac.cppcheck.net/ticket/10164, I think it would be good to investigate this.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Suppressing critical errors like unknownMacro or syntxError is not a good idea. Those errors should be addressed by e.g. using a library, passing defiinitions (-U, -D), or making the corresponding header files available to cppcheck.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's unrelated to this issue. But, I am relying on --force to define my macro configuration. (I am using --force so that I can perform "whole project" analysis on all configurations for the unusedFunctionscheck and system level misra checks. )
But with --force -D__GNUC__=9the analysis start by checking an empty macro configuration first:
That causes some of the macro definitions to not be included in that step. And that is why I had unknownMacro suppression in the first place. - I thought it was benign to suppress it, because only one unknown macro was reported. Now I noticed there are more macros and more other issues underreported.
In general, I would prefer to use --project which would alleviate undefined macros problem that I have with --force. But --project option doesn't work correctly with misra addon - it only checks the last configuration. Here are some testcases showcasing that issue https://github.com/danmar/cppcheck/pull/6551
Last edit: Dzid 2024-07-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
In a large project I have a macro which CppCheck 2.3 does not know about. The result of this is that CppCheck in this case does not detect a CWE 762 “Mismatching allocation and deallocation” error.
Below sample code can reproduce the error. When CWE_762 is undefined no 762 error is reported.
If I include the #define or remove the “CWE_762("test");” the error is detected correctly.
This must be a bug?
Thanks! It seems that Cppcheck bails out, I am not sure if there is some good reasons for that or not. I created ticket https://trac.cppcheck.net/ticket/10164, I think it would be good to investigate this.
The worst part for me is that if run the check with
--suppress=unknownMacro
I don't get any indication that there are any errors (not just CWE 762).Examples of underreported errors:
[constVariablePointer]
[misra-c2012-17.3]
[resp_len]
[misra-c2012-17.3]
[misra-config]
[unusedFunction]
Last edit: Dzid 2024-07-26
that is desired behaviour by some users.
if you use option --safety cppcheck should not allow suppressing critical errors.
Suppressing critical errors like
unknownMacro
orsyntxError
is not a good idea. Those errors should be addressed by e.g. using a library, passing defiinitions (-U
,-D
), or making the corresponding header files available to cppcheck.It's unrelated to this issue. But, I am relying on
--force
to define my macro configuration. (I am using--force
so that I can perform "whole project" analysis on all configurations for theunusedFunctions
check and system level misra checks. )But with
--force -D__GNUC__=9
the analysis start by checking an empty macro configuration first:That causes some of the macro definitions to not be included in that step. And that is why I had
unknownMacro
suppression in the first place. - I thought it was benign to suppress it, because only one unknown macro was reported. Now I noticed there are more macros and more other issues underreported.In general, I would prefer to use
--project
which would alleviate undefined macros problem that I have with--force
. But--project
option doesn't work correctly with misra addon - it only checks the last configuration. Here are some testcases showcasing that issue https://github.com/danmar/cppcheck/pull/6551Last edit: Dzid 2024-07-27