In trying to make a CFG to enforce checking this status I made the following rule.
<functionname="MyFunc"><use-retval/></function>
However it only works for the first line below. Not the 2nd. Our code requires it report this error for the 2nd line.
MyFunc(Args);
MyStruct->MyFunc(Args);
I also attempted a much longer function definition with every qualified name configuration I could think of. But it gave the same results. (Forgive me, we program entierly in C, so I'm rusty with this programming syntax)
Would anyone know how to get CppCheck to report for our case?
P.S. - Checking the CppCheck codebase I noticed that there are files for processing classes, but I didn't see one for structs. Is it possible that CppCheck does not understand our particular situation?
Thank you,
Scott
Last edit: Scott H 2018-05-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
$ g++ struct_function.cpp -o struct_function
$ ./struct_function
testfunc says hi!
$ ./cppcheck --enable=all --library=struct_function.cfg --check-library --debug-warnings struct_function.cpp
Checking struct_function.cpp ...
[struct_function.cpp:5]: (debug) valueflow.cpp:3343:valueFlowFunctionReturn bailout: functionreturn; nontrivial function body
(information) Cppcheck cannot find all the include files (use --check-config for details)
IMHO this is a false negative.
You can see that Cppcheck does not complain about a missing configuration for teststruct::testfunc which would be the case if the according function configuration is not present. So this should be the correct way to specify struct functions i guess.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have created ticket 8595.
Your case is a bit more complex like the one i described in the ticket. Maybe there is a bit more to fix/enhance so it works for your code too, i am not sure.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
And i nearly forgot about this ticket: https://trac.cppcheck.net/ticket/8290
I do not know if Cppcheck sees the implementation in your case and i am not sure if Cppcheck is able to track the function pointers, but if it does this could be a reason it ignores the function configuration.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello all,
Sorry if this has been answered somewhere already. Searches on Google and directly on the forum were both unproductive.
In our C code we have many cases of the following in our code where the int returned is a status.
In trying to make a CFG to enforce checking this status I made the following rule.
However it only works for the first line below. Not the 2nd. Our code requires it report this error for the 2nd line.
I also attempted a much longer function definition with every qualified name configuration I could think of. But it gave the same results. (Forgive me, we program entierly in C, so I'm rusty with this programming syntax)
Would anyone know how to get CppCheck to report for our case?
P.S. - Checking the CppCheck codebase I noticed that there are files for processing classes, but I didn't see one for structs. Is it possible that CppCheck does not understand our particular situation?
Thank you,
Scott
Last edit: Scott H 2018-05-21
Even without function pointers i get no warning:
struct_function.cpp:
struct_function.cfg:
output:
IMHO this is a false negative.
You can see that Cppcheck does not complain about a missing configuration for
teststruct::testfunc
which would be the case if the according function configuration is not present. So this should be the correct way to specify struct functions i guess.I have created ticket 8595.
Your case is a bit more complex like the one i described in the ticket. Maybe there is a bit more to fix/enhance so it works for your code too, i am not sure.
And i nearly forgot about this ticket: https://trac.cppcheck.net/ticket/8290
I do not know if Cppcheck sees the implementation in your case and i am not sure if Cppcheck is able to track the function pointers, but if it does this could be a reason it ignores the function configuration.