Removed more indendation counters.

This commit is contained in:
PKEuS 2012-01-15 12:31:49 +01:00
parent d891d1ce5d
commit c294b15360
5 changed files with 10 additions and 63 deletions

View File

@ -442,15 +442,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
// the function is external and it's neither friend nor inherited virtual function.
// assume all variables that are passed to it are initialized..
else {
unsigned int indentlevel2 = 0;
for (const Token *tok = ftok->tokAt(2); tok; tok = tok->next()) {
if (tok->str() == "(")
++indentlevel2;
else if (tok->str() == ")") {
if (indentlevel2 == 0)
break;
--indentlevel2;
}
for (const Token *tok = ftok->tokAt(2); tok && tok != ftok->next()->link(); tok = tok->next()) {
if (tok->isName()) {
assignVar(tok->str(), scope, usage);
}

View File

@ -434,23 +434,14 @@ void CheckNullPointer::nullPointerLinkedList()
const std::string varname(tok2->str());
// Check usage of dereferenced variable in the loop..
unsigned int indentlevel3 = 0;
for (const Token *tok3 = tok1->next()->link(); tok3; tok3 = tok3->next()) {
if (tok3->str() == "{")
++indentlevel3;
else if (tok3->str() == "}") {
if (indentlevel3 <= 1)
break;
--indentlevel3;
}
for (const Token *tok3 = i->classStart; tok3 && tok3 != i->classEnd; tok3 = tok3->next()) {
// TODO: are there false negatives for "while ( %varid% ||"
else if (Token::Match(tok3, "while ( %varid% &&|)", varid)) {
if (Token::Match(tok3, "while ( %varid% &&|)", varid)) {
// Make sure there is a "break" or "return" inside the loop.
// Without the "break" a null pointer could be dereferenced in the
// for statement.
// indentlevel4 is a counter for { and }. When scanning the code with tok4
unsigned int indentlevel4 = indentlevel3;
unsigned int indentlevel4 = 1;
for (const Token *tok4 = tok3->next()->link(); tok4; tok4 = tok4->next()) {
if (tok4->str() == "{")
++indentlevel4;

View File

@ -1747,8 +1747,7 @@ void CheckOther::checkVariableScope()
continue;
// Walk through all tokens..
unsigned int indentlevel = 0;
for (const Token *tok = scope->classStart; tok; tok = tok->next()) {
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
// Skip function local class and struct declarations..
if ((tok->str() == "class") || (tok->str() == "struct") || (tok->str() == "union")) {
for (const Token *tok2 = tok; tok2; tok2 = tok2->next()) {
@ -1764,15 +1763,7 @@ void CheckOther::checkVariableScope()
break;
}
else if (tok->str() == "{") {
++indentlevel;
} else if (tok->str() == "}") {
if (!indentlevel)
break;
--indentlevel;
}
if (indentlevel > 0 && Token::Match(tok, "[{};]")) {
if (Token::Match(tok, "[{};]")) {
// First token of statement..
const Token *tok1 = tok->next();
if (! tok1)

View File

@ -265,35 +265,16 @@ void CheckStl::stlOutOfBounds()
continue;
// check if the for loop condition is wrong
unsigned int indent = 0;
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) {
if (tok2->str() == "(")
++indent;
else if (tok2->str() == ")") {
if (indent == 0)
break;
--indent;
}
for (const Token *tok2 = tok->tokAt(2); tok2 && tok2 != tok->next()->link(); tok2 = tok2->next()) {
if (Token::Match(tok2, "; %var% <= %var% . size ( ) ;")) {
// Count { and } for tok3
unsigned int indent3 = 0;
// variable id for loop variable.
unsigned int numId = tok2->next()->varId();
// variable id for the container variable
unsigned int varId = tok2->tokAt(3)->varId();
for (const Token *tok3 = tok2->tokAt(8); tok3; tok3 = tok3->next()) {
if (tok3->str() == "{")
++indent3;
else if (tok3->str() == "}") {
if (indent3 <= 1)
break;
--indent3;
} else if (tok3->varId() == varId) {
for (const Token *tok3 = tok2->tokAt(8); tok3 && tok3 != i->classEnd; tok3 = tok3->next()) {
if (tok3->varId() == varId) {
if (Token::simpleMatch(tok3->next(), ". size ( )"))
break;
else if (Token::Match(tok3->next(), "[ %varid% ]", numId))

View File

@ -830,15 +830,7 @@ private:
// Check that the variable hasn't been initialized and
// that it isn't initialized in the body..
if (varid1.find(varid) == varid1.end()) {
unsigned int indentlevel = 0;
for (const Token *tok3 = tok2->tokAt(5); tok3; tok3 = tok3->next()) {
if (tok3->str() == "{")
++indentlevel;
else if (tok3->str() == "}") {
if (indentlevel == 0)
break;
--indentlevel;
}
for (const Token *tok3 = tok2->tokAt(5); tok3 && tok3 != tok2->linkAt(4); tok3 = tok3->next()) {
if (tok3->varId() == varid) {
varid = 0; // variable is used.. maybe it's initialized. clear the variable id.
break;