Fixed #1632 (false positive: unintialized variable)

This commit is contained in:
Daniel Marjamäki 2010-04-28 21:33:11 +02:00
parent d3b5c30c6c
commit 2666aad207
3 changed files with 38 additions and 7 deletions

29
lib/executionpath.cpp Executable file → Normal file
View File

@ -22,6 +22,7 @@
#include <memory>
#include <set>
#include <iterator>
#include <iostream>
// default : bail out if the condition is has variable handling
@ -62,6 +63,20 @@ bool ExecutionPath::parseCondition(const Token &tok, std::list<ExecutionPath *>
}
void ExecutionPath::print() const
{
std::cout << " varId=" << varId
<< " numberOfIf=" << numberOfIf
<< "\n";
}
static void printchecks(const std::list<ExecutionPath *> &checks)
{
for (std::list<ExecutionPath *>::const_iterator it = checks.begin(); it != checks.end(); ++it)
(*it)->print();
}
static void checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &checks)
{
if (!tok || tok->str() == "}" || checks.empty())
@ -222,16 +237,16 @@ static void checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &c
{
std::set<unsigned int> countif2;
std::list<ExecutionPath *> c;
if (checks.size() == 1)
c.push_back(checks.front()->copy());
else if (!checks.empty())
if (!checks.empty())
{
std::list<ExecutionPath *>::const_iterator it;
it = checks.begin();
while (++it != checks.end())
for (it = checks.begin(); it != checks.end(); ++it)
{
c.push_back((*it)->copy());
countif2.insert((*it)->varId);
if ((*it)->varId != 0)
{
c.push_back((*it)->copy());
countif2.insert((*it)->varId);
}
}
}
checkExecutionPaths_(tok->next(), c);

View File

@ -50,6 +50,9 @@ public:
/** Implement this in each derived class. This function must create a copy of the current instance */
virtual ExecutionPath *copy() = 0;
/** print checkdata */
void print() const;
/** number of if blocks */
unsigned int numberOfIf;

View File

@ -1570,6 +1570,19 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void foo(long verbose,bool bFlag)\n"
"{\n"
" double t;\n"
" if (bFlag)\n"
" {\n"
" if (verbose)\n"
" t = 1;\n"
" if (verbose)\n"
" std::cout << (12-t);\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// switch..
checkUninitVar("char * f()\n"
"{\n"