Uninitialized variables: Fixed false positives when passing allocated pointer to function
This commit is contained in:
parent
ef15e40de5
commit
a4f9cb78d5
|
@ -1693,9 +1693,9 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
|
|||
return true;
|
||||
if (Token::Match(argStart, "const %type% & %var% [,)]"))
|
||||
return true;
|
||||
if (pointer && !address && Token::Match(argStart, "struct| %type% * %var% [,)]"))
|
||||
if (pointer && !address && !alloc && Token::Match(argStart, "struct| %type% * %var% [,)]"))
|
||||
return true;
|
||||
if ((pointer || address) && Token::Match(argStart, "const struct| %type% * %var% [,)]"))
|
||||
if ((pointer || address) && !alloc && Token::Match(argStart, "const struct| %type% * %var% [,)]"))
|
||||
return true;
|
||||
if ((pointer || address) && Token::Match(argStart, "const %type% %var% [") && Token::Match(argStart->linkAt(3), "] [,)]"))
|
||||
return true;
|
||||
|
|
|
@ -3278,6 +3278,14 @@ private:
|
|||
" return ab->a;\n" // error
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: ab.a\n", errout.str());
|
||||
|
||||
checkUninitVar2("struct AB { int a; int b; };\n"
|
||||
"void do_something(struct AB *ab);\n" // unknown function
|
||||
"int f() {\n"
|
||||
" struct AB *ab = malloc(sizeof(struct AB));\n"
|
||||
" do_something(ab);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void syntax_error() { // Ticket #5073
|
||||
|
|
Loading…
Reference in New Issue