为什么 CPP 检查不显示任何错误

Why is CPP Check not showing any ERRORS?

本文关键字:任何 错误 显示 CPP 检查 为什么      更新时间:2023-10-16

This

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 参数,因为它执行以下操作:

-

-检查配置检查 cpppcheck 配置。普通代码此标志禁用分析。

如果您定义了UNIT_TEST并且此特定代码段因此未处于活动状态,则不会显示任何问题。

此外,如果要查看错误,

则应指定"--enable=all",因为越界被归类为错误,而不是样式。未使用的变量(如您的示例中给出的(是一个样式问题。

运行 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>