简体   繁体   中英

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

For example in the code below x is declared on the stack, but it is not initialised and it is therefore indeterminate. The address of x is then passed to func2. Since the value of x is not defined, the behavior of func2 cannot be certain.

Can Coverity issue a warning for this type of error?

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.

Check how you execute cov-analyze. You can specify your own checkers configuration there by --dc-config parameter.

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. ie x = 0 in func1 above

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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