General code tweaking, nothing strange.
This commit is contained in:
parent
0b6e7d7dd2
commit
ba5909ef1d
|
@ -1246,7 +1246,7 @@ void CheckBufferOverrun::checkReadlinkBufferUsage(const Token* tok, const Token
|
||||||
void CheckBufferOverrun::checkGlobalAndLocalVariable()
|
void CheckBufferOverrun::checkGlobalAndLocalVariable()
|
||||||
{
|
{
|
||||||
// check all known fixed size arrays first by just looking them up
|
// check all known fixed size arrays first by just looking them up
|
||||||
for (size_t i = 1; i <= _tokenizer->varIdCount(); i++) {
|
for (unsigned int i = 1; i <= _tokenizer->varIdCount(); i++) {
|
||||||
const Variable *var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(i);
|
const Variable *var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(i);
|
||||||
if (var && var->isArray() && var->dimension(0) > 0) {
|
if (var && var->isArray() && var->dimension(0) > 0) {
|
||||||
ArrayInfo arrayInfo(var, _tokenizer);
|
ArrayInfo arrayInfo(var, _tokenizer);
|
||||||
|
@ -2100,7 +2100,7 @@ void CheckBufferOverrun::executionPaths()
|
||||||
{
|
{
|
||||||
// Parse all variables and extract array info..
|
// Parse all variables and extract array info..
|
||||||
std::map<unsigned int, ArrayInfo> arrayInfo;
|
std::map<unsigned int, ArrayInfo> arrayInfo;
|
||||||
for (size_t i = 1; i <= _tokenizer->varIdCount(); i++) {
|
for (unsigned int i = 1; i <= _tokenizer->varIdCount(); i++) {
|
||||||
const Variable *var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(i);
|
const Variable *var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(i);
|
||||||
if (var && var->isArray() && var->dimension(0) > 0)
|
if (var && var->isArray() && var->dimension(0) > 0)
|
||||||
arrayInfo[i] = ArrayInfo(var, _tokenizer);
|
arrayInfo[i] = ArrayInfo(var, _tokenizer);
|
||||||
|
|
|
@ -290,7 +290,7 @@ void CheckOther::warningOldStylePointerCast()
|
||||||
!Token::Match(tok, "( const| %type% * ) (| new"))
|
!Token::Match(tok, "( const| %type% * ) (| new"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int addToIndex = 0;
|
unsigned char addToIndex = 0;
|
||||||
if (tok->tokAt(1)->str() == "const")
|
if (tok->tokAt(1)->str() == "const")
|
||||||
addToIndex = 1;
|
addToIndex = 1;
|
||||||
|
|
||||||
|
@ -363,7 +363,7 @@ void CheckOther::checkSizeofForArrayParameter()
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "sizeof ( %var% )") || Token::Match(tok, "sizeof %var%")) {
|
if (Token::Match(tok, "sizeof ( %var% )") || Token::Match(tok, "sizeof %var%")) {
|
||||||
int tokIdx = 1;
|
unsigned short tokIdx = 1;
|
||||||
if (tok->tokAt(tokIdx)->str() == "(") {
|
if (tok->tokAt(tokIdx)->str() == "(") {
|
||||||
++tokIdx;
|
++tokIdx;
|
||||||
}
|
}
|
||||||
|
@ -432,7 +432,7 @@ void CheckOther::checkSizeofForStrncmpSize()
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, pattern1) || Token::Match(tok, pattern2)) {
|
if (Token::Match(tok, pattern1) || Token::Match(tok, pattern2)) {
|
||||||
int tokIdx = 7;
|
unsigned short tokIdx = 7;
|
||||||
if (tok->tokAt(tokIdx)->str() == "(")
|
if (tok->tokAt(tokIdx)->str() == "(")
|
||||||
++tokIdx;
|
++tokIdx;
|
||||||
const Token *tokVar = tok->tokAt(tokIdx);
|
const Token *tokVar = tok->tokAt(tokIdx);
|
||||||
|
@ -1082,7 +1082,7 @@ void CheckOther::invalidFunctionUsage()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Locate the third parameter of the function call..
|
// Locate the third parameter of the function call..
|
||||||
int param = 1;
|
unsigned int param = 1;
|
||||||
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) {
|
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) {
|
||||||
if (tok2->str() == "(")
|
if (tok2->str() == "(")
|
||||||
tok2 = tok2->link();
|
tok2 = tok2->link();
|
||||||
|
@ -1125,14 +1125,14 @@ void CheckOther::invalidFunctionUsage()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// is any source buffer overlapping the target buffer?
|
// is any source buffer overlapping the target buffer?
|
||||||
int parlevel = 0;
|
unsigned int parlevel = 0;
|
||||||
while ((tok2 = tok2->next()) != NULL) {
|
while ((tok2 = tok2->next()) != NULL) {
|
||||||
if (tok2->str() == "(")
|
if (tok2->str() == "(")
|
||||||
++parlevel;
|
++parlevel;
|
||||||
else if (tok2->str() == ")") {
|
else if (tok2->str() == ")") {
|
||||||
--parlevel;
|
if (!parlevel)
|
||||||
if (parlevel < 0)
|
|
||||||
break;
|
break;
|
||||||
|
--parlevel;
|
||||||
} else if (parlevel == 0 && Token::Match(tok2, ", %varid% [,)]", varid)) {
|
} else if (parlevel == 0 && Token::Match(tok2, ", %varid% [,)]", varid)) {
|
||||||
sprintfOverlappingDataError(tok2->next(), tok2->next()->str());
|
sprintfOverlappingDataError(tok2->next(), tok2->next()->str());
|
||||||
break;
|
break;
|
||||||
|
@ -1410,7 +1410,7 @@ void CheckOther::checkVariableScope()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Walk through all tokens..
|
// Walk through all tokens..
|
||||||
int indentlevel = 0;
|
unsigned int indentlevel = 0;
|
||||||
for (const Token *tok = scope->classStart; tok; 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")) {
|
||||||
|
@ -1430,9 +1430,9 @@ void CheckOther::checkVariableScope()
|
||||||
else if (tok->str() == "{") {
|
else if (tok->str() == "{") {
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
} else if (tok->str() == "}") {
|
} else if (tok->str() == "}") {
|
||||||
|
if (!indentlevel)
|
||||||
|
break;
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
if (indentlevel == 0)
|
|
||||||
break;;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indentlevel > 0 && Token::Match(tok, "[{};]")) {
|
if (indentlevel > 0 && Token::Match(tok, "[{};]")) {
|
||||||
|
@ -1477,7 +1477,7 @@ void CheckOther::lookupVar(const Token *tok1, const std::string &varname)
|
||||||
// Check if the variable is used in this indentlevel..
|
// Check if the variable is used in this indentlevel..
|
||||||
bool used1 = false; // used in one sub-scope -> reducable
|
bool used1 = false; // used in one sub-scope -> reducable
|
||||||
bool used2 = false; // used in more sub-scopes -> not reducable
|
bool used2 = false; // used in more sub-scopes -> not reducable
|
||||||
int indentlevel = 0;
|
unsigned int indentlevel = 0;
|
||||||
int parlevel = 0;
|
int parlevel = 0;
|
||||||
bool for_or_while = false; // is sub-scope a "for/while/etc". anything that is not "if"
|
bool for_or_while = false; // is sub-scope a "for/while/etc". anything that is not "if"
|
||||||
while (tok) {
|
while (tok) {
|
||||||
|
@ -1673,15 +1673,15 @@ void CheckOther::checkCharVariable()
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
// Check usage of char variable..
|
// Check usage of char variable..
|
||||||
int indentlevel = 0;
|
unsigned int indentlevel = 0;
|
||||||
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
||||||
if (tok2->str() == "{")
|
if (tok2->str() == "{")
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
|
|
||||||
else if (tok2->str() == "}") {
|
else if (tok2->str() == "}") {
|
||||||
--indentlevel;
|
if (!indentlevel)
|
||||||
if (indentlevel <= 0)
|
|
||||||
break;
|
break;
|
||||||
|
--indentlevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isPointer) {
|
if (!isPointer) {
|
||||||
|
@ -1977,9 +1977,9 @@ void CheckOther::checkMisusedScopedObject()
|
||||||
if (tok->str() == "{") {
|
if (tok->str() == "{") {
|
||||||
++depth;
|
++depth;
|
||||||
} else if (tok->str() == "}") {
|
} else if (tok->str() == "}") {
|
||||||
--depth;
|
|
||||||
if (depth == 0)
|
if (depth == 0)
|
||||||
break;
|
break;
|
||||||
|
--depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok, "[;{}] %var% (")
|
if (Token::Match(tok, "[;{}] %var% (")
|
||||||
|
|
|
@ -1164,8 +1164,9 @@ void Tokenizer::simplifyTypedef()
|
||||||
if (tok->strAt(offset + 1) == "(")
|
if (tok->strAt(offset + 1) == "(")
|
||||||
++offset;
|
++offset;
|
||||||
else if (Token::simpleMatch(tok->tokAt(offset), "( * (")) {
|
else if (Token::simpleMatch(tok->tokAt(offset), "( * (")) {
|
||||||
|
++offset;
|
||||||
pointers.push_back("*");
|
pointers.push_back("*");
|
||||||
offset += 2;
|
++offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok->tokAt(offset)->link()->strAt(-2) == "*")
|
if (tok->tokAt(offset)->link()->strAt(-2) == "*")
|
||||||
|
@ -4041,7 +4042,7 @@ void Tokenizer::simplifySizeof()
|
||||||
sz = sizeOfType(tok->tokAt(2));
|
sz = sizeOfType(tok->tokAt(2));
|
||||||
if (sz == 0)
|
if (sz == 0)
|
||||||
continue;
|
continue;
|
||||||
sz = sz * static_cast<unsigned long>(MathLib::toLongNumber(tok->strAt(4)));
|
sz = sz * static_cast<unsigned int>(MathLib::toLongNumber(tok->strAt(4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sz > 0) {
|
if (sz > 0) {
|
||||||
|
@ -8353,13 +8354,11 @@ void Tokenizer::simplifyComma()
|
||||||
if (Token::simpleMatch(tok, "for (") ||
|
if (Token::simpleMatch(tok, "for (") ||
|
||||||
Token::Match(tok, "=|enum {")) {
|
Token::Match(tok, "=|enum {")) {
|
||||||
tok = tok->next()->link();
|
tok = tok->next()->link();
|
||||||
if (!tok)
|
|
||||||
break;
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok->str() == "(") {
|
if (tok->str() == "(" || tok->str() == "[") {
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -8372,7 +8371,7 @@ void Tokenizer::simplifyComma()
|
||||||
if (tok2->str() == "<")
|
if (tok2->str() == "<")
|
||||||
++comparelevel;
|
++comparelevel;
|
||||||
else if (tok2->str() == ">") {
|
else if (tok2->str() == ">") {
|
||||||
if (comparelevel <= 1) {
|
if (!comparelevel) {
|
||||||
tok = tok2;
|
tok = tok2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -9680,7 +9679,7 @@ void Tokenizer::printUnknownTypes()
|
||||||
|
|
||||||
std::set<std::string> unknowns;
|
std::set<std::string> unknowns;
|
||||||
|
|
||||||
for (size_t i = 1; i <= _varId; ++i) {
|
for (unsigned int i = 1; i <= _varId; ++i) {
|
||||||
const Variable *var = _symbolDatabase->getVariableFromVarId(i);
|
const Variable *var = _symbolDatabase->getVariableFromVarId(i);
|
||||||
|
|
||||||
// is unknown record type?
|
// is unknown record type?
|
||||||
|
|
Loading…
Reference in New Issue