Fixed 'possible null pointer dereference' warning messages

This commit is contained in:
Daniel Marjamäki 2011-07-28 08:12:21 +02:00
parent d2c0e5e7e6
commit dc629b4c39
6 changed files with 12 additions and 5 deletions

View File

@ -811,6 +811,8 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
// Check if the function deallocates the variable..
while (ftok && (ftok->str() != "{"))
ftok = ftok->next();
if (!ftok)
return 0;
Token *func = getcode(ftok->tokAt(1), callstack, parameterVarid, alloctype, dealloctype, false, sz);
//simplifycode(func, all);
const Token *func_ = func;

View File

@ -876,6 +876,8 @@ void CheckOther::invalidFunctionUsage()
const Token *tok2 = tok->tokAt(3);
while (tok2 && tok2->str() != ",")
tok2 = tok2->next();
if (!tok2)
continue;
// is any source buffer overlapping the target buffer?
int parlevel = 0;

View File

@ -101,7 +101,7 @@ public:
checkOther.checkComparisonOfBoolWithInt();
checkOther.checkSwitchCaseFallThrough();
checkOther.checkAlwaysTrueOrFalseStringCompare();
checkOther.checkAssignBoolToPointer();
}

View File

@ -763,7 +763,8 @@ void CheckStl::if_find()
while (decl && !Token::Match(decl, "[;{}(,]"))
decl = decl->previous();
decl = decl->next();
if (decl)
decl = decl->next();
// stl container
if (Token::Match(decl, "const| std :: %var% < %type% > &|*| %varid%", varid))
@ -1137,8 +1138,10 @@ void CheckStl::checkAutoPointer()
{
tok3 = tok3->next();
}
if (!tok3)
continue;
tok3 = tok3->previous()->previous();
if (Token::Match(tok3->previous(), "[ ] )"))
if (Token::simpleMatch(tok3->previous(), "[ ] )"))
{
autoPointerArrayError(tok2->next());
}

View File

@ -1088,7 +1088,7 @@ public:
}
// found simple function..
if (tok2->link() == tok->tokAt(2))
if (tok2 && tok2->link() == tok->tokAt(2))
func.insert(tok->next()->str());
}
}

View File

@ -36,7 +36,7 @@ private:
void run()
{
TEST_CASE(assignBoolToPointer);
TEST_CASE(zeroDiv1);
TEST_CASE(zeroDiv2);
TEST_CASE(zeroDiv3);