Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is CPP Check not showing any ERRORS?

This

cppcheck --enable=style --inconclusive --check-config --xml --xml-version=2 -v -I.. -I../mocks -I../gmock -I../gtest -DUNIT_TEST ../src

results in this

<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
  <cppcheck version="1.52"/>
  <errors>
Checking ../src/AppMain.cpp...
  </errors>
</results>

Obviously, I am doing something wrong - but what?

Btw, I am certain that the code has problems, but just to be sure, I pasted these two lines into it

 char a[10];
 a[10] = 0;

And there was no report of referencing out of bounds

like image 933
Mawg says reinstate Monica Avatar asked Jan 07 '23 08:01

Mawg says reinstate Monica


1 Answers

Without a minimal working example to reproduce the problem it is hard to help.

First of all, remove the check-config parameter since it does the following:

--check-config Check cppcheck configuration. The normal code analysis is disabled by this flag.

To know the sourcecode is important, because if you define UNIT_TEST and this particular snipet is not active because of this, it wont show any problems.

Furthermore, you should specify "--enable=all" if you want to see errors because out-of-bounds is classified as error, not as style. Unused variable (as given in your example) is a style problem though.

Running cppcheck (v1.72)

cppcheck --enable=all --inconclusive --xml-version=2 -v foo.cpp

on this

void main()
{
  char a[10];
  a[10] = 0;
}

results in the following output for me

<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
    <cppcheck version="1.72"/>
    <errors>
        <error id="unreadVariable" severity="style" msg="Variable &apos;a&apos; is assigned a value that is never used." verbose="Variable &apos;a&apos; is assigned a value that is never used.">
            <location file="foo.cpp" line="5"/>
        </error>
        <error id="arrayIndexOutOfBounds" severity="error" msg="Array &apos;a[10]&apos; accessed at index 10, which is out of bounds." verbose="Array &apos;a[10]&apos; accessed at index 10, which is out of bounds.">
            <location file="foo.cpp" line="5"/>
        </error>
    </errors>
</results>
like image 194
x29a Avatar answered Jan 15 '23 07:01

x29a