I am new to cppcheck and have tried some examples C code.
The one thing than I cannot understand is that the manual specifies that the std.cfg library is always used, but if have used (for example) the
atol function but I leave out any parameters, like i = atol(), or specify more than 1 parameter, then cppcheck does not give any warnings, although I use --enable=all.
If you write i = atol() then Cppcheck assumes that you are calling a atol function that does not take any arguments... and there is no configuration for that function.
If you don't have such function then your compiler should write some syntax error.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But please give me an example were I can see that cppcheck give me a warning/error when I make a mistake using one of the functions that is checked in std.cfg, like atol.
My understanding is that cppcheck will use the xml tags in std.cfg to test the code against, for example what does cppcheck check for the atol function, given the tags in std.cfg? :
hmm.. we have some old simplifications for atol that is preventing Cppcheck to detect problems. This code atol("123") is simplified to 123 too early. We'll have to fix this.
Hi,
I am new to cppcheck and have tried some examples C code.
The one thing than I cannot understand is that the manual specifies that the std.cfg library is always used, but if have used (for example) the
atol function but I leave out any parameters, like i = atol(), or specify more than 1 parameter, then cppcheck does not give any warnings, although I use --enable=all.
I can see the atol function in the std.cfg:
<function name="atol">
<use-retval>
<pure>
<returnvalue type="long int">
<noreturn>false</noreturn>
<leak-ignore>
<arg nr="1">
<not-null>
<not-uninit>
<strz>
</strz></not-uninit></not-null></arg>
</leak-ignore></returnvalue></pure></use-retval></function>
What I am missing?
If you write
i = atol()
then Cppcheck assumes that you are calling aatol
function that does not take any arguments... and there is no configuration for that function.If you don't have such function then your compiler should write some syntax error.
OK,
But please give me an example were I can see that cppcheck give me a warning/error when I make a mistake using one of the functions that is checked in std.cfg, like atol.
My understanding is that cppcheck will use the xml tags in std.cfg to test the code against, for example what does cppcheck check for the atol function, given the tags in std.cfg? :
I would assume <use-retval> means that cppcheck should check if the return value of the atol is used/assigned, like</use-retval>
int i=0;
i= atol("123");
should return no errors/warnings, but
int i=0;
atol("123");
should return a warning/error?
hmm.. we have some old simplifications for
atol
that is preventing Cppcheck to detect problems. This codeatol("123")
is simplified to123
too early. We'll have to fix this.I created this ticket: https://trac.cppcheck.net/ticket/9090
Here is another code example that will output various warnings thanks to those configurations