Removed more indendation counters.
This commit is contained in:
parent
d891d1ce5d
commit
c294b15360
|
@ -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.
|
// the function is external and it's neither friend nor inherited virtual function.
|
||||||
// assume all variables that are passed to it are initialized..
|
// assume all variables that are passed to it are initialized..
|
||||||
else {
|
else {
|
||||||
unsigned int indentlevel2 = 0;
|
for (const Token *tok = ftok->tokAt(2); tok && tok != ftok->next()->link(); tok = tok->next()) {
|
||||||
for (const Token *tok = ftok->tokAt(2); tok; tok = tok->next()) {
|
|
||||||
if (tok->str() == "(")
|
|
||||||
++indentlevel2;
|
|
||||||
else if (tok->str() == ")") {
|
|
||||||
if (indentlevel2 == 0)
|
|
||||||
break;
|
|
||||||
--indentlevel2;
|
|
||||||
}
|
|
||||||
if (tok->isName()) {
|
if (tok->isName()) {
|
||||||
assignVar(tok->str(), scope, usage);
|
assignVar(tok->str(), scope, usage);
|
||||||
}
|
}
|
||||||
|
|
|
@ -434,23 +434,14 @@ void CheckNullPointer::nullPointerLinkedList()
|
||||||
const std::string varname(tok2->str());
|
const std::string varname(tok2->str());
|
||||||
|
|
||||||
// Check usage of dereferenced variable in the loop..
|
// Check usage of dereferenced variable in the loop..
|
||||||
unsigned int indentlevel3 = 0;
|
for (const Token *tok3 = i->classStart; tok3 && tok3 != i->classEnd; tok3 = tok3->next()) {
|
||||||
for (const Token *tok3 = tok1->next()->link(); tok3; tok3 = tok3->next()) {
|
|
||||||
if (tok3->str() == "{")
|
|
||||||
++indentlevel3;
|
|
||||||
else if (tok3->str() == "}") {
|
|
||||||
if (indentlevel3 <= 1)
|
|
||||||
break;
|
|
||||||
--indentlevel3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: are there false negatives for "while ( %varid% ||"
|
// 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.
|
// Make sure there is a "break" or "return" inside the loop.
|
||||||
// Without the "break" a null pointer could be dereferenced in the
|
// Without the "break" a null pointer could be dereferenced in the
|
||||||
// for statement.
|
// for statement.
|
||||||
// indentlevel4 is a counter for { and }. When scanning the code with tok4
|
// 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()) {
|
for (const Token *tok4 = tok3->next()->link(); tok4; tok4 = tok4->next()) {
|
||||||
if (tok4->str() == "{")
|
if (tok4->str() == "{")
|
||||||
++indentlevel4;
|
++indentlevel4;
|
||||||
|
|
|
@ -1747,8 +1747,7 @@ void CheckOther::checkVariableScope()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Walk through all tokens..
|
// Walk through all tokens..
|
||||||
unsigned int indentlevel = 0;
|
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
||||||
for (const Token *tok = scope->classStart; tok; tok = tok->next()) {
|
|
||||||
// Skip function local class and struct declarations..
|
// Skip function local class and struct declarations..
|
||||||
if ((tok->str() == "class") || (tok->str() == "struct") || (tok->str() == "union")) {
|
if ((tok->str() == "class") || (tok->str() == "struct") || (tok->str() == "union")) {
|
||||||
for (const Token *tok2 = tok; tok2; tok2 = tok2->next()) {
|
for (const Token *tok2 = tok; tok2; tok2 = tok2->next()) {
|
||||||
|
@ -1764,15 +1763,7 @@ void CheckOther::checkVariableScope()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (tok->str() == "{") {
|
if (Token::Match(tok, "[{};]")) {
|
||||||
++indentlevel;
|
|
||||||
} else if (tok->str() == "}") {
|
|
||||||
if (!indentlevel)
|
|
||||||
break;
|
|
||||||
--indentlevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (indentlevel > 0 && Token::Match(tok, "[{};]")) {
|
|
||||||
// First token of statement..
|
// First token of statement..
|
||||||
const Token *tok1 = tok->next();
|
const Token *tok1 = tok->next();
|
||||||
if (! tok1)
|
if (! tok1)
|
||||||
|
|
|
@ -265,35 +265,16 @@ void CheckStl::stlOutOfBounds()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// check if the for loop condition is wrong
|
// check if the for loop condition is wrong
|
||||||
unsigned int indent = 0;
|
for (const Token *tok2 = tok->tokAt(2); tok2 && tok2 != tok->next()->link(); tok2 = tok2->next()) {
|
||||||
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) {
|
|
||||||
if (tok2->str() == "(")
|
|
||||||
++indent;
|
|
||||||
|
|
||||||
else if (tok2->str() == ")") {
|
|
||||||
if (indent == 0)
|
|
||||||
break;
|
|
||||||
--indent;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Token::Match(tok2, "; %var% <= %var% . size ( ) ;")) {
|
if (Token::Match(tok2, "; %var% <= %var% . size ( ) ;")) {
|
||||||
// Count { and } for tok3
|
|
||||||
unsigned int indent3 = 0;
|
|
||||||
|
|
||||||
// variable id for loop variable.
|
// variable id for loop variable.
|
||||||
unsigned int numId = tok2->next()->varId();
|
unsigned int numId = tok2->next()->varId();
|
||||||
|
|
||||||
// variable id for the container variable
|
// variable id for the container variable
|
||||||
unsigned int varId = tok2->tokAt(3)->varId();
|
unsigned int varId = tok2->tokAt(3)->varId();
|
||||||
|
|
||||||
for (const Token *tok3 = tok2->tokAt(8); tok3; tok3 = tok3->next()) {
|
for (const Token *tok3 = tok2->tokAt(8); tok3 && tok3 != i->classEnd; tok3 = tok3->next()) {
|
||||||
if (tok3->str() == "{")
|
if (tok3->varId() == varId) {
|
||||||
++indent3;
|
|
||||||
else if (tok3->str() == "}") {
|
|
||||||
if (indent3 <= 1)
|
|
||||||
break;
|
|
||||||
--indent3;
|
|
||||||
} else if (tok3->varId() == varId) {
|
|
||||||
if (Token::simpleMatch(tok3->next(), ". size ( )"))
|
if (Token::simpleMatch(tok3->next(), ". size ( )"))
|
||||||
break;
|
break;
|
||||||
else if (Token::Match(tok3->next(), "[ %varid% ]", numId))
|
else if (Token::Match(tok3->next(), "[ %varid% ]", numId))
|
||||||
|
|
|
@ -830,15 +830,7 @@ private:
|
||||||
// Check that the variable hasn't been initialized and
|
// Check that the variable hasn't been initialized and
|
||||||
// that it isn't initialized in the body..
|
// that it isn't initialized in the body..
|
||||||
if (varid1.find(varid) == varid1.end()) {
|
if (varid1.find(varid) == varid1.end()) {
|
||||||
unsigned int indentlevel = 0;
|
for (const Token *tok3 = tok2->tokAt(5); tok3 && tok3 != tok2->linkAt(4); tok3 = tok3->next()) {
|
||||||
for (const Token *tok3 = tok2->tokAt(5); tok3; tok3 = tok3->next()) {
|
|
||||||
if (tok3->str() == "{")
|
|
||||||
++indentlevel;
|
|
||||||
else if (tok3->str() == "}") {
|
|
||||||
if (indentlevel == 0)
|
|
||||||
break;
|
|
||||||
--indentlevel;
|
|
||||||
}
|
|
||||||
if (tok3->varId() == varid) {
|
if (tok3->varId() == varid) {
|
||||||
varid = 0; // variable is used.. maybe it's initialized. clear the variable id.
|
varid = 0; // variable is used.. maybe it's initialized. clear the variable id.
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue