Uninitialized vars: handle printf a little better. Ticket: #3050
This commit is contained in:
parent
c7d0beefa8
commit
2601733ff7
|
@ -118,6 +118,15 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
|
|||
if (functionNames2.find(tok.str()) != functionNames2.end())
|
||||
var.push_back(tok.tokAt(4));
|
||||
}
|
||||
|
||||
// TODO: Handle sprintf/printf better.
|
||||
if (Token::Match(&tok, "printf ( %str% , %var% ,|)") && tok.tokAt(4)->varId() > 0)
|
||||
{
|
||||
const std::string &formatstr(tok.tokAt(2)->str());
|
||||
const std::string::size_type pos = formatstr.find("%");
|
||||
if (pos != std::string::npos && formatstr.compare(pos,2,"%s") == 0)
|
||||
var.push_back(tok.tokAt(4));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1075,6 +1075,12 @@ private:
|
|||
" char *b = (a+2) & 7;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("void f() {\n" // Ticket #3050
|
||||
" char a[2];\n"
|
||||
" printf(\"%s\", a);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
|
||||
}
|
||||
|
||||
// alloc..
|
||||
|
|
Loading…
Reference in New Issue