Merge branch 'master' of git@github.com:danmar/cppcheck
This commit is contained in:
commit
276c0a7b2f
|
@ -46,44 +46,48 @@ static CheckAutoVariables instance;
|
||||||
// _callStack used when parsing into subfunctions.
|
// _callStack used when parsing into subfunctions.
|
||||||
|
|
||||||
|
|
||||||
bool CheckAutoVariables::error_av(const Token* left, const Token* right)
|
bool CheckAutoVariables::errorAv(const Token* left, const Token* right)
|
||||||
{
|
{
|
||||||
std::string left_var = left->str();
|
std::string left_var = left->str();
|
||||||
std::string right_var = right->str();
|
std::string right_var = right->str();
|
||||||
std::list<std::string>::iterator it_fp;
|
std::list<std::string>::iterator it_fp;
|
||||||
|
|
||||||
for (it_fp = fp_list.begin();it_fp != fp_list.end();it_fp++)
|
for (it_fp = fp_list.begin();it_fp != fp_list.end();++it_fp)
|
||||||
{
|
{
|
||||||
std::string vname = (*it_fp);
|
std::string vname = (*it_fp);
|
||||||
//cout << "error_av " << vname << " " << left_var << endl;
|
|
||||||
|
//The left argument is a formal parameter
|
||||||
if (vname == left_var)
|
if (vname == left_var)
|
||||||
{
|
{
|
||||||
//cout << "Beccato" << endl;
|
//cout << "Beccato" << endl;
|
||||||
break; //The left argument is a formal parameter
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//The left argument is NOT a formal parameter
|
||||||
if (it_fp == fp_list.end())
|
if (it_fp == fp_list.end())
|
||||||
return false; //The left argument is NOT a formal parameter
|
return false;
|
||||||
|
|
||||||
std::list<std::string>::iterator id_vd;
|
std::list<std::string>::iterator id_vd;
|
||||||
for (id_vd = vd_list.begin();id_vd != vd_list.end();id_vd++)
|
for (id_vd = vd_list.begin();id_vd != vd_list.end();++id_vd)
|
||||||
{
|
{
|
||||||
std::string vname = (*id_vd);
|
std::string vname = (*id_vd);
|
||||||
|
//The left argument is a variable declaration
|
||||||
if (vname == right_var)
|
if (vname == right_var)
|
||||||
break; //The left argument is a variable declaration
|
break;
|
||||||
}
|
}
|
||||||
|
//The left argument is NOT a variable declaration
|
||||||
if (id_vd == vd_list.end())
|
if (id_vd == vd_list.end())
|
||||||
return false; //The left argument is NOT a variable declaration
|
return false;
|
||||||
//If I reach this point there is a wrong assignement of an auto-variable to an effective parameter of a function
|
//If I reach this point there is a wrong assignement of an auto-variable to an effective parameter of a function
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
bool CheckAutoVariables::is_auto_var(const Token* t)
|
bool CheckAutoVariables::isAutoVar(const Token* t)
|
||||||
{
|
{
|
||||||
std::list<std::string>::iterator id_vd;
|
std::list<std::string>::iterator id_vd;
|
||||||
std::string v = t->str();
|
std::string v = t->str();
|
||||||
for (id_vd = vd_list.begin();id_vd != vd_list.end();id_vd++)
|
for (id_vd = vd_list.begin();id_vd != vd_list.end();++id_vd)
|
||||||
{
|
{
|
||||||
std::string vname = (*id_vd);
|
std::string vname = (*id_vd);
|
||||||
if (vname == v)
|
if (vname == v)
|
||||||
|
@ -188,7 +192,7 @@ void CheckAutoVariables::autoVariables()
|
||||||
}
|
}
|
||||||
else if (bindent > 0 && Token::Match(tok, "%var% = & %var%")) //Critical assignement
|
else if (bindent > 0 && Token::Match(tok, "%var% = & %var%")) //Critical assignement
|
||||||
{
|
{
|
||||||
if (error_av(tok->tokAt(0), tok->tokAt(3)))
|
if (errorAv(tok->tokAt(0), tok->tokAt(3)))
|
||||||
reportError(tok,
|
reportError(tok,
|
||||||
"error",
|
"error",
|
||||||
"autoVariables",
|
"autoVariables",
|
||||||
|
@ -196,7 +200,7 @@ void CheckAutoVariables::autoVariables()
|
||||||
}
|
}
|
||||||
else if (bindent > 0 && Token::Match(tok, "%var% [ %any% ] = & %var%")) //Critical assignement
|
else if (bindent > 0 && Token::Match(tok, "%var% [ %any% ] = & %var%")) //Critical assignement
|
||||||
{
|
{
|
||||||
if (error_av(tok->tokAt(0), tok->tokAt(6)))
|
if (errorAv(tok->tokAt(0), tok->tokAt(6)))
|
||||||
reportError(tok,
|
reportError(tok,
|
||||||
"error",
|
"error",
|
||||||
"autoVariables",
|
"autoVariables",
|
||||||
|
@ -204,7 +208,7 @@ void CheckAutoVariables::autoVariables()
|
||||||
}
|
}
|
||||||
else if (bindent > 0 && Token::Match(tok, "return & %var%")) //Critical return
|
else if (bindent > 0 && Token::Match(tok, "return & %var%")) //Critical return
|
||||||
{
|
{
|
||||||
if (is_auto_var(tok->tokAt(2)))
|
if (isAutoVar(tok->tokAt(2)))
|
||||||
reportError(tok,
|
reportError(tok,
|
||||||
"error",
|
"error",
|
||||||
"autoVariables",
|
"autoVariables",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Cppcheck - A tool for static C/C++ code analysis
|
* Cppcheck - A tool for static C/C++ code analysis
|
||||||
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
|
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
|
||||||
* Leandro Penz, Kimmo Varis, Vesa Pikki
|
* Leandro Penz, Kimmo Varis, Vesa Pikki, Gianluca Scacco
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -51,8 +51,8 @@ public:
|
||||||
private:
|
private:
|
||||||
std::list<std::string> fp_list;
|
std::list<std::string> fp_list;
|
||||||
std::list<std::string> vd_list;
|
std::list<std::string> vd_list;
|
||||||
bool error_av(const Token* left, const Token* right);
|
bool errorAv(const Token* left, const Token* right);
|
||||||
bool is_auto_var(const Token* t);
|
bool isAutoVar(const Token* t);
|
||||||
void addVD(const Token* t);
|
void addVD(const Token* t);
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages()
|
||||||
|
|
Loading…
Reference in New Issue