0
#include "test.h"

static int test(){
 test_t i;
 init(i);
}

static test_t init(test_t const a){
 test_c(&a);
 return a;
}

When I use Cppcheck to check this file ,it reports uninitialized variable at init(i);. But it does not report uninitialized variable when I delete the declaration of init .

#include "test.h"

static int test(){
    test_t i;
    init(i);
}

Is there any solution for cppcheck reports uninitialized variable when calling external functions?

Jw.zhang
  • 1
  • 1
  • How does the second version even compile? If the tool doesn't know what `init` is then how can it tell that `init(i)` is making use of the variable? It could as well be a macro `#define init(x) x=0` or whatever. – Lundin Jun 10 '21 at 09:11
  • this is a example ,function init is defined in other file – Jw.zhang Jun 10 '21 at 09:14
  • But where is it _declared_? A function declaration needs to be visible inside the same translation unit and placed before the `test` definition. – Lundin Jun 10 '21 at 09:16
  • Yes, you are right. The same translation unit is the key of this problem – Jw.zhang Jun 10 '21 at 09:39
  • Since CppCheck might interpret this as C++, it could think of `init(test_t &p)` and then `i` might not be used unitialized. – the busybee Jun 10 '21 at 11:35

0 Answers0