Fixed #9594 (False positive: Using argument that points at uninitialized variable when write only)

This commit is contained in:
Daniel Marjamäki 2020-02-04 18:56:01 +01:00
parent c8df734c07
commit ca3095746c
2 changed files with 12 additions and 1 deletions

View File

@ -990,6 +990,8 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
possibleParent = getAstParentSkipPossibleCastAndAddressOf(possibleParent, &unknown);
if (possibleParent && Token::Match(possibleParent->previous(), "decltype|sizeof ("))
return false;
if (possibleParent && isLikelyStreamRead(mTokenizer->isCPP(), possibleParent))
return false;
}
if (Token::Match(possibleParent, "[(,]")) {
if (unknown)
@ -1401,7 +1403,7 @@ Check::FileInfo *CheckUninitVar::getFileInfo() const
return nullptr;
MyFileInfo *fileInfo = new MyFileInfo;
fileInfo->unsafeUsage = unsafeUsage ;
fileInfo->unsafeUsage = unsafeUsage;
return fileInfo;
}

View File

@ -4690,6 +4690,15 @@ private:
" f(&x);\n"
"}");
ASSERT_EQUALS("", errout.str());
ctu("void f(int *v) {\n"
" std::cin >> *v;\n"
"}\n"
"int main() {\n"
" int x;\n"
" f(&x);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};