Why is CPP Check not showing any ERRORS?
Asked Answered
A

1

6

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

Admirable answered 19/10, 2015 at 15:22 Comment(2)
I think it could be useful for you to try out PVS-Studio. It is as simple as CppCheck in usage. I have pasted these two strings and the analyzer gave me such a message: V557 Array overrun is possible. The '10' index is pointing beyond array bound.Walkover
Thanks for teh tip )+1), however CPPcheck is the mandated tool around here and I also need it to work with Jenkins. Plus, I doubt that the company would pay for a toll (which doesn't even list its prices - you have to give them contact details), when we already use a good (the most popular), free oneAdmirable
P
10

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>
Patchy answered 15/1, 2016 at 14:55 Comment(2)
Yeah, it seems to be undocumented, but it exists. The cli also mentions it, at least on a more current version.Patchy
i should not have linked against master, the highlighted line moved of course. Check this to see what i meant in the comment abovePatchy

© 2022 - 2024 — McMap. All rights reserved.