为什么 CPP Check 没有显示任何错误?

Why is CPP Check not showing any ERRORS?

这个

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

结果

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

显然,我做错了什么 - 但是什么?

顺便说一句,我确定代码有问题,但为了确定,我将这两行粘贴到其中

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

并且没有引用越界的报告

没有最小的工作示例来重现问题,很难提供帮助。

首先,删除 check-config 参数,因为它 does the following:

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

了解源代码很重要,因为如果您定义 UNIT_TEST 并且此特定代码段因此不活动,它不会显示任何问题。

此外,如果您想查看错误,您应该指定“--enable=all”,因为 out-of-bounds 被归类为错误,而不是样式。未使用的变量(如您的示例中所示)是一个样式问题。

运行 cppcheck (v1.72)

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

在此

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

我的结果如下

<?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>