Remove unnecessary includes
Also add a unit test related to #3427 Also improve the description text in checkclass and remove unused variable.
This commit is contained in:
parent
8e94e2261b
commit
dca03c3ce2
|
@ -21,7 +21,6 @@
|
||||||
#include "threadexecutor.h"
|
#include "threadexecutor.h"
|
||||||
#include "preprocessor.h"
|
#include "preprocessor.h"
|
||||||
#include "errorlogger.h"
|
#include "errorlogger.h"
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdlib> // EXIT_SUCCESS and EXIT_FAILURE
|
#include <cstdlib> // EXIT_SUCCESS and EXIT_FAILURE
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
#include "cppcheckexecutor.h"
|
#include "cppcheckexecutor.h"
|
||||||
#include "threadexecutor.h"
|
#include "threadexecutor.h"
|
||||||
#include "cppcheck.h"
|
#include "cppcheck.h"
|
||||||
#include <iostream>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#ifdef THREADING_MODEL_FORK
|
#ifdef THREADING_MODEL_FORK
|
||||||
|
#include <iostream>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
|
@ -23,8 +23,7 @@
|
||||||
#include "checkautovariables.h"
|
#include "checkautovariables.h"
|
||||||
#include "symboldatabase.h"
|
#include "symboldatabase.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <list>
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
#include <set>
|
|
||||||
|
|
||||||
/// @addtogroup Checks
|
/// @addtogroup Checks
|
||||||
/// @{
|
/// @{
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "checkboost.h"
|
#include "checkboost.h"
|
||||||
#include "symboldatabase.h"
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
// Register this check class (by creating a static instance of it)
|
// Register this check class (by creating a static instance of it)
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
@ -30,12 +30,8 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <cstring>
|
|
||||||
#include <cctype>
|
|
||||||
#include <climits>
|
|
||||||
|
|
||||||
#include <cassert> // <- assert
|
#include <cassert> // <- assert
|
||||||
#include <cstdlib> // <- strtoul
|
#include <cstdlib>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -2160,7 +2156,6 @@ void CheckBufferOverrun::arrayIndexThenCheck()
|
||||||
return;
|
return;
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "%var% [ %var% ]")) {
|
if (Token::Match(tok, "%var% [ %var% ]")) {
|
||||||
const std::string arrayName(tok->str());
|
|
||||||
const std::string indexName(tok->strAt(2));
|
const std::string indexName(tok->strAt(2));
|
||||||
|
|
||||||
// skip array index..
|
// skip array index..
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include "errorlogger.h"
|
#include "errorlogger.h"
|
||||||
#include "symboldatabase.h"
|
#include "symboldatabase.h"
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,10 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
#include "settings.h"
|
|
||||||
#include "symboldatabase.h"
|
|
||||||
|
|
||||||
class Token;
|
class Token;
|
||||||
|
class Scope;
|
||||||
|
class Function;
|
||||||
|
|
||||||
/// @addtogroup Checks
|
/// @addtogroup Checks
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -147,8 +147,8 @@ private:
|
||||||
return "Check the code for each class.\n"
|
return "Check the code for each class.\n"
|
||||||
"* Missing constructors\n"
|
"* Missing constructors\n"
|
||||||
"* Are all variables initialized by the constructors?\n"
|
"* Are all variables initialized by the constructors?\n"
|
||||||
"* [[CheckMemset|Warn if memset, memcpy etc are used on a class]]\n"
|
"* Warn if memset, memcpy etc are used on a class\n"
|
||||||
//"* If it's a base class, check that the destructor is virtual\n"
|
"* If it's a base class, check that the destructor is virtual\n"
|
||||||
"* Are there unused private functions\n"
|
"* Are there unused private functions\n"
|
||||||
"* 'operator=' should return reference to self\n"
|
"* 'operator=' should return reference to self\n"
|
||||||
"* 'operator=' should check for assignment to self\n"
|
"* 'operator=' should check for assignment to self\n"
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "checkmemoryleak.h"
|
#include "checkmemoryleak.h"
|
||||||
|
#include "symboldatabase.h"
|
||||||
#include "mathlib.h"
|
#include "mathlib.h"
|
||||||
#include "tokenize.h"
|
#include "tokenize.h"
|
||||||
|
|
||||||
|
|
|
@ -35,13 +35,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
#include "symboldatabase.h"
|
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class Token;
|
class Token;
|
||||||
|
class Scope;
|
||||||
|
|
||||||
/// @addtogroup Core
|
/// @addtogroup Core
|
||||||
/// @{
|
/// @{
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
/// @addtogroup Checks
|
/// @addtogroup Checks
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
/// @addtogroup Core
|
/// @addtogroup Core
|
||||||
/// @{
|
/// @{
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "settings.h"
|
|
||||||
#include "suppressions.h"
|
#include "suppressions.h"
|
||||||
|
|
||||||
class Token;
|
class Token;
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include "tokenize.h"
|
#include "tokenize.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cstring>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <cctype> // std::isdigit, std::isalnum, etc
|
#include <cctype> // std::isdigit, std::isalnum, etc
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,8 @@
|
||||||
#include "errorlogger.h"
|
#include "errorlogger.h"
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <algorithm>
|
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
|
||||||
// Define ULLONG_MAX and LLONG_MAX for Borland
|
// Define ULLONG_MAX and LLONG_MAX for Borland
|
||||||
|
|
|
@ -1606,7 +1606,7 @@ private:
|
||||||
checkVirtualDestructor("class Base\n"
|
checkVirtualDestructor("class Base\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
"~Base() {}\n"
|
" ~Base() {}\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"class A : private Base\n"
|
"class A : private Base\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1619,7 +1619,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" ~B() { int a; }\n"
|
" ~B() { int a; }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Class A which is inherited by class B does not have a virtual destructor\n",
|
TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Class Base which is inherited by class B does not have a virtual destructor\n",
|
||||||
"", errout.str());
|
"", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,8 @@
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <map>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
// use tinyxml with STL
|
// use tinyxml with STL
|
||||||
#include <tinyxml.h>
|
#include <tinyxml.h>
|
||||||
|
|
|
@ -1394,6 +1394,14 @@ private:
|
||||||
" const char *c = f().c_str();\n"
|
" const char *c = f().c_str();\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous usage of c_str(). The returned value by c_str() is invalid after this call.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous usage of c_str(). The returned value by c_str() is invalid after this call.\n", errout.str());
|
||||||
|
|
||||||
|
|
||||||
|
check("const char* foo() {\n"
|
||||||
|
" static std::string text;\n"
|
||||||
|
" text = \"hello world\n\";\n"
|
||||||
|
" return text.c_str();\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str()); // #3427
|
||||||
}
|
}
|
||||||
|
|
||||||
void autoPointer() {
|
void autoPointer() {
|
||||||
|
|
|
@ -26,10 +26,9 @@
|
||||||
#include "threadexecutor.h"
|
#include "threadexecutor.h"
|
||||||
#include "cppcheckexecutor.h"
|
#include "cppcheckexecutor.h"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <vector>
|
||||||
|
|
||||||
extern std::ostringstream errout;
|
extern std::ostringstream errout;
|
||||||
extern std::ostringstream output;
|
extern std::ostringstream output;
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,11 @@
|
||||||
|
|
||||||
#ifndef TestUtilsH
|
#ifndef TestUtilsH
|
||||||
#define TestUtilsH
|
#define TestUtilsH
|
||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "tokenize.h"
|
#include "tokenize.h"
|
||||||
#include "token.h"
|
|
||||||
|
class Token;
|
||||||
|
|
||||||
class givenACodeSampleToTokenize {
|
class givenACodeSampleToTokenize {
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue