简体   繁体   English

覆盖率。 配置覆盖率以检查声明的变量在用作指针之前是否已初始化

[英]Coverity. Configure coverity to check that a declared variable is initialized before usage as a pointer

Looking for a way to configure Coverity such that it will ensure that a declared variable on the stack is initialised prior to its address being passed to another function寻找一种配置 Coverity 的方法,以确保堆栈上声明的变量在其地址传递给另一个 function 之前被初始化

For example in the code below x is declared on the stack, but it is not initialised and it is therefore indeterminate.例如,在下面的代码中 x 在堆栈上声明,但它没有被初始化,因此它是不确定的。 The address of x is then passed to func2.然后将 x 的地址传递给 func2。 Since the value of x is not defined, the behavior of func2 cannot be certain.由于 x 的值未定义,因此 func2 的行为无法确定。

Can Coverity issue a warning for this type of error? Coverity 能否针对此类错误发出警告?

void func1(uint32_t* val)
{
    uint32_t x; /*x is not initialised!! */
    func2(val, &x);
}

void func2(uint32_t* val, uint32_t* x)
{
    uint32_t y;
    y = (*x) + (*v);
}

Strange you don't have it, but having UNINIT checker enabled should do the trick.奇怪的是你没有它,但启用 UNINIT 检查器应该可以解决问题。

Check how you execute cov-analyze.检查您如何执行 cov-analyze。 You can specify your own checkers configuration there by --dc-config parameter.您可以通过 --dc-config 参数在那里指定您自己的检查器配置。

Thanks for the help on this one.感谢您对此的帮助。 The only real solution in this particular case is to ensure that the object is initialised prior to passing its address to a function.在这种特殊情况下,唯一真正的解决方案是确保在将 object 的地址传递给 function 之前对其进行初始化。 ie x = 0 in func1 above即上面func1中的x = 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM