【问题标题】:Why is CPP Check not showing any ERRORS?为什么 CPP Check 没有显示任何错误?
【发布时间】:2015-10-19 15:22:05
【问题描述】:

这个

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;

并且没有引用越界的报告

【问题讨论】:

  • 我认为试用 PVS-Studio 可能对您有用。使用起来就像 CppCheck 一样简单。我已经粘贴了这两个字符串,分析器给了我这样的消息:V557 Array overrun is possible。 “10”索引指向数组边界之外。
  • 感谢您的提示 )+1),但是 CPPcheck 是这里的强制工具,我也需要它来与 Jenkins 一起工作。另外,我怀疑该公司会支付通行费(甚至没有列出其价格 - 你必须给他们联系方式),当我们已经使用一个好的(最受欢迎的),免费的

标签: c++ xml static-code-analysis cppcheck


【解决方案1】:

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

首先,去掉check-config参数,因为它does the following:

--check-config 检查 cppcheck 配置。正常代码 此标志禁用分析。

了解源代码很重要,因为如果您定义 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>

【讨论】:

  • 是的,它似乎没有记录,但是it exists。 cli 也提到了它,至少在更新的版本上。
  • 我不应该与 master 链接,突出显示的行当然移动了。检查this 看看我在上面评论中的意思
猜你喜欢
  • 2020-05-11
  • 1970-01-01
  • 2017-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-03
  • 2014-10-29
  • 1970-01-01
相关资源
最近更新 更多