Search code examples
c++xmlstatic-code-analysiscppcheck

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


Solution

  • 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.

    If you define UNIT_TEST and this particular snippet is not active because of this, it won't 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>