Refactorized CheckOther::checkSizeofForArrayParameter: Use symboldatabase to detect arrays.

This commit is contained in:
PKEuS 2012-05-24 00:39:16 -07:00
parent ffb9342084
commit 334fc16f29
1 changed files with 3 additions and 27 deletions

View File

@ -455,39 +455,15 @@ void CheckOther::checkSizeofForArrayParameter()
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
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% !![")) {
const Token* varTok = tok->next(); const Token* varTok = tok->next();
if (varTok->str() == "(") { if (varTok->str() == "(") {
varTok = varTok->next(); varTok = varTok->next();
} }
if (varTok->varId() > 0) { if (varTok->varId() > 0) {
const Variable *var = symbolDatabase->getVariableFromVarId(varTok->varId()); const Variable *var = symbolDatabase->getVariableFromVarId(varTok->varId());
if (var) { if (var && var->isArray() && var->isArgument()) {
const Token *declTok = var->nameToken();
if (declTok && declTok->next()->str() == "[") {
declTok = declTok->next()->link()->next();
// multidimensional array
while (declTok->str() == "[") {
declTok = declTok->link()->next();
}
if (!(Token::Match(declTok, "= %str%")) && !(Token::simpleMatch(declTok, "= {")) && declTok->str() != ";") {
if (declTok->str() == ",") {
while (declTok->str() != ";") {
if (declTok->str() == ")") {
sizeofForArrayParameterError(tok); sizeofForArrayParameterError(tok);
break;
}
if (Token::Match(declTok, "(|[|{")) {
declTok = declTok->link();
}
declTok = declTok->next();
}
}
}
if (declTok->str() == ")") {
sizeofForArrayParameterError(tok);
}
}
} }
} }
} }