Merge branch 'master' of git://github.com/danmar/cppcheck
This commit is contained in:
commit
415aaca6dd
|
@ -2401,9 +2401,12 @@ void CheckMemoryLeakInClass::check()
|
||||||
if (scope->isClassOrStruct()) {
|
if (scope->isClassOrStruct()) {
|
||||||
std::list<Variable>::const_iterator var;
|
std::list<Variable>::const_iterator var;
|
||||||
for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var) {
|
for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var) {
|
||||||
if (!var->isStatic() && var->nameToken()->previous()->str() == "*") {
|
if (!var->isStatic() && var->isPointer()) {
|
||||||
// allocation but no deallocation of private variables in public function..
|
// allocation but no deallocation of private variables in public function..
|
||||||
if (var->nameToken()->tokAt(-2)->isStandardType()) {
|
const Token *tok = var->typeStartToken();
|
||||||
|
if (tok->str() == "const")
|
||||||
|
tok = tok->next();
|
||||||
|
if (tok && tok->isStandardType()) {
|
||||||
if (var->isPrivate())
|
if (var->isPrivate())
|
||||||
checkPublicFunctions(&(*scope), var->nameToken());
|
checkPublicFunctions(&(*scope), var->nameToken());
|
||||||
|
|
||||||
|
|
|
@ -1036,7 +1036,7 @@ void CheckNullPointer::nullConstantDereference()
|
||||||
nullPointerError(*it);
|
nullPointerError(*it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok, "std :: string ( 0 )"))
|
} else if (Token::simpleMatch(tok, "std :: string ( 0 )"))
|
||||||
nullPointerError(tok);
|
nullPointerError(tok);
|
||||||
else if (Token::Match(tok, "%var% ( 0 )")) {
|
else if (Token::Match(tok, "%var% ( 0 )")) {
|
||||||
const Variable* var = symbolDatabase->getVariableFromVarId(tok->varId());
|
const Variable* var = symbolDatabase->getVariableFromVarId(tok->varId());
|
||||||
|
|
|
@ -1706,7 +1706,7 @@ void CheckOther::checkUnsignedDivision()
|
||||||
if ((isUnsigned(var1) && isSigned(var2)) || (isUnsigned(var2) && isSigned(var1))) {
|
if ((isUnsigned(var1) && isSigned(var2)) || (isUnsigned(var2) && isSigned(var1))) {
|
||||||
udivError(tok->next(), true);
|
udivError(tok->next(), true);
|
||||||
}
|
}
|
||||||
} else if (!ifTok && Token::Match(tok, "if ("))
|
} else if (!ifTok && Token::simpleMatch(tok, "if ("))
|
||||||
ifTok = tok->next()->link()->next()->link();
|
ifTok = tok->next()->link()->next()->link();
|
||||||
else if (ifTok == tok)
|
else if (ifTok == tok)
|
||||||
ifTok = 0;
|
ifTok = 0;
|
||||||
|
@ -2534,12 +2534,12 @@ void CheckOther::checkDoubleFree()
|
||||||
else if (Token::Match(tok, "%var% (") && !Token::Match(tok, "printf|sprintf|snprintf|fprintf|if|while")) {
|
else if (Token::Match(tok, "%var% (") && !Token::Match(tok, "printf|sprintf|snprintf|fprintf|if|while")) {
|
||||||
|
|
||||||
// If this is a new function definition, clear all variables
|
// If this is a new function definition, clear all variables
|
||||||
if (Token::Match(tok->next()->link(), ") {")) {
|
if (Token::simpleMatch(tok->next()->link(), ") {")) {
|
||||||
freedVariables.clear();
|
freedVariables.clear();
|
||||||
closeDirVariables.clear();
|
closeDirVariables.clear();
|
||||||
}
|
}
|
||||||
// If it is a function call, then clear those variables in its argument list
|
// If it is a function call, then clear those variables in its argument list
|
||||||
else if (Token::Match(tok->next()->link(), ") ;")) {
|
else if (Token::simpleMatch(tok->next()->link(), ") ;")) {
|
||||||
for (const Token* tok2 = tok->tokAt(2); tok2 != tok->linkAt(1); tok2 = tok2->next()) {
|
for (const Token* tok2 = tok->tokAt(2); tok2 != tok->linkAt(1); tok2 = tok2->next()) {
|
||||||
if (Token::Match(tok2, "%var%")) {
|
if (Token::Match(tok2, "%var%")) {
|
||||||
unsigned int var = tok2->varId();
|
unsigned int var = tok2->varId();
|
||||||
|
|
|
@ -3857,9 +3857,9 @@ void Tokenizer::simplifyRealloc()
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
else if (Token::Match(tok, "[;{}] %var% = realloc (")) {
|
else if (Token::Match(tok, "[;{}] %var% = realloc (")) {
|
||||||
tok = tok->tokAt(3);
|
tok = tok->tokAt(3);
|
||||||
if (Token::Match(tok->next(), "( 0 ,")) {
|
if (Token::simpleMatch(tok->next(), "( 0 ,")) {
|
||||||
//no "x = realloc(0,);"
|
//no "x = realloc(0,);"
|
||||||
if (!Token::Match(tok->next()->link(), ") ;") || tok->next()->link()->previous() == tok->tokAt(3))
|
if (!Token::simpleMatch(tok->next()->link(), ") ;") || tok->next()->link()->previous() == tok->tokAt(3))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// delete "0 ,"
|
// delete "0 ,"
|
||||||
|
@ -3897,7 +3897,6 @@ void Tokenizer::simplifyRealloc()
|
||||||
void Tokenizer::simplifyFlowControl()
|
void Tokenizer::simplifyFlowControl()
|
||||||
{
|
{
|
||||||
unsigned int indentlevel = 0;
|
unsigned int indentlevel = 0;
|
||||||
Token *beginindent = 0;
|
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||||
if (tok->str() == "(" || tok->str() == "[") {
|
if (tok->str() == "(" || tok->str() == "[") {
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
|
@ -3909,7 +3908,6 @@ void Tokenizer::simplifyFlowControl()
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
beginindent = tok;
|
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
} else if (tok->str() == "}") {
|
} else if (tok->str() == "}") {
|
||||||
if (!indentlevel)
|
if (!indentlevel)
|
||||||
|
@ -3920,22 +3918,18 @@ void Tokenizer::simplifyFlowControl()
|
||||||
if (!indentlevel)
|
if (!indentlevel)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Token::Match(tok, "goto %var% ;")) {
|
if (Token::Match(tok,"continue|break ;")) {
|
||||||
tok = tok->tokAt(2);
|
|
||||||
eraseDeadCode(tok, beginindent->link());
|
|
||||||
|
|
||||||
} else if (Token::Match(tok,"continue|break ;")) {
|
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
eraseDeadCode(tok, beginindent->link());
|
eraseDeadCode(tok, 0);
|
||||||
|
|
||||||
} else if (Token::Match(tok,"return|throw|exit|abort")) {
|
} else if (Token::Match(tok,"return|throw|exit|abort|goto")) {
|
||||||
//catch the first ';'
|
//catch the first ';'
|
||||||
for (Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
for (Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
||||||
if (tok2->str() == "(" || tok2->str() == "[") {
|
if (tok2->str() == "(" || tok2->str() == "[") {
|
||||||
tok2 = tok2->link();
|
tok2 = tok2->link();
|
||||||
} else if (tok2->str() == ";") {
|
} else if (tok2->str() == ";") {
|
||||||
tok = tok2;
|
tok = tok2;
|
||||||
eraseDeadCode(tok, beginindent->link());
|
eraseDeadCode(tok, 0);
|
||||||
break;
|
break;
|
||||||
} else if (Token::Match(tok2, "[{}]"))
|
} else if (Token::Match(tok2, "[{}]"))
|
||||||
break; //Wrong code.
|
break; //Wrong code.
|
||||||
|
|
Loading…
Reference in New Issue