Fix some clang analyzer messages.

CheckMemoryLeak: two redundant assignments, should be clarified;
TemplateSimplifier: same;
Tokenizer: same.
This commit is contained in:
Edoardo Prezioso 2012-10-24 03:09:42 +02:00
parent b50e1f4451
commit 11b0047063
3 changed files with 8 additions and 6 deletions

View File

@ -879,7 +879,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
if (alloc != CheckMemoryLeak::No) { if (alloc != CheckMemoryLeak::No) {
addtoken(&rettail, tok, "realloc"); addtoken(&rettail, tok, "realloc");
addtoken(&rettail, tok, ";"); addtoken(&rettail, tok, ";");
realloc = true; //TODO: this assignment is redundant, should be fixed
/*realloc = true;*/
tok = tok->tokAt(2); tok = tok->tokAt(2);
if (Token::Match(tok, "%var% (")) if (Token::Match(tok, "%var% ("))
tok = tok->next()->link(); tok = tok->next()->link();
@ -964,7 +965,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
AllocType dealloc = getDeallocationType(tok, varid); AllocType dealloc = getDeallocationType(tok, varid);
if (dealloc != No && tok->str() == "fcloseall" && alloctype != dealloc) if (dealloc != No && tok->str() == "fcloseall" && alloctype != dealloc)
dealloc = No; //TODO: this assignment is redundant, should be fixed
/*dealloc = No*/;
else if (dealloc != No) { else if (dealloc != No) {
addtoken(&rettail, tok, "dealloc"); addtoken(&rettail, tok, "dealloc");

View File

@ -340,7 +340,7 @@ std::set<std::string> TemplateSimplifier::expandSpecialized(Token *tokens)
{ {
std::ostringstream ostr; std::ostringstream ostr;
const Token *tok3 = tok2; const Token *tok3 = tok2;
for (tok3 = tok2; tok3 && tok3->str() != ">"; tok3 = tok3->next()) { for (; tok3 && tok3->str() == ">"; tok3 = tok3->next()) {
if (tok3 != tok2) if (tok3 != tok2)
ostr << " "; ostr << " ";
ostr << tok3->str(); ostr << tok3->str();
@ -812,7 +812,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
Token::Match(tok->previous(), "[(=,] 1 ||")) { Token::Match(tok->previous(), "[(=,] 1 ||")) {
unsigned int par = 0; unsigned int par = 0;
const Token *tok2 = tok; const Token *tok2 = tok;
for (tok2 = tok; tok2; tok2 = tok2->next()) { for (; tok2; tok2 = tok2->next()) {
if (tok2->str() == "(") if (tok2->str() == "(")
++par; ++par;
else if (tok2->str() == ")") { else if (tok2->str() == ")") {

View File

@ -5491,7 +5491,7 @@ void Tokenizer::simplifyIfAssign()
if (iswhile) { if (iswhile) {
unsigned int indentlevel = 0; unsigned int indentlevel = 0;
Token *tok3 = tok2; Token *tok3 = tok2;
for (tok3 = tok2; tok3; tok3 = tok3->next()) { for (; tok3; tok3 = tok3->next()) {
if (tok3->str() == "{") if (tok3->str() == "{")
++indentlevel; ++indentlevel;
else if (tok3->str() == "}") { else if (tok3->str() == "}") {
@ -6024,7 +6024,7 @@ bool Tokenizer::simplifyKnownVariables()
bool Tokenizer::simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2, Token **_tok3, std::string &value, unsigned int &valueVarId, bool &valueIsPointer, bool floatvar) bool Tokenizer::simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2, Token **_tok3, std::string &value, unsigned int &valueVarId, bool &valueIsPointer, bool floatvar)
{ {
Token *tok2 = *_tok2; Token *tok2 = *_tok2;
Token *tok3 = *_tok3; Token *tok3 = NULL;
if (Token::simpleMatch(tok2->tokAt(-2), "for (")) { if (Token::simpleMatch(tok2->tokAt(-2), "for (")) {
// only specific for loops is handled // only specific for loops is handled