Small refactoring: replace NULL by nullptr, remove redundant static keyword, Tokenizer::setVarId() uses const variable 'notstart'
This commit is contained in:
parent
9a42f52915
commit
f762affea0
|
@ -580,10 +580,10 @@ namespace {
|
||||||
hThread,
|
hThread,
|
||||||
&stack,
|
&stack,
|
||||||
&context,
|
&context,
|
||||||
NULL,
|
nullptr,
|
||||||
pSymFunctionTableAccess64,
|
pSymFunctionTableAccess64,
|
||||||
pSymGetModuleBase64,
|
pSymGetModuleBase64,
|
||||||
NULL
|
nullptr
|
||||||
);
|
);
|
||||||
if (!result) // official end...
|
if (!result) // official end...
|
||||||
break;
|
break;
|
||||||
|
@ -748,7 +748,7 @@ int CppCheckExecutor::check_wrapper(CppCheck& cppcheck, int argc, const char* co
|
||||||
segv_stack.ss_sp = mytstack;
|
segv_stack.ss_sp = mytstack;
|
||||||
segv_stack.ss_flags = 0;
|
segv_stack.ss_flags = 0;
|
||||||
segv_stack.ss_size = MYSTACKSIZE;
|
segv_stack.ss_size = MYSTACKSIZE;
|
||||||
sigaltstack(&segv_stack, NULL);
|
sigaltstack(&segv_stack, nullptr);
|
||||||
|
|
||||||
// install signal handler
|
// install signal handler
|
||||||
struct sigaction act;
|
struct sigaction act;
|
||||||
|
@ -756,7 +756,7 @@ int CppCheckExecutor::check_wrapper(CppCheck& cppcheck, int argc, const char* co
|
||||||
act.sa_flags=SA_SIGINFO|SA_ONSTACK;
|
act.sa_flags=SA_SIGINFO|SA_ONSTACK;
|
||||||
act.sa_sigaction=CppcheckSignalHandler;
|
act.sa_sigaction=CppcheckSignalHandler;
|
||||||
for (std::map<int, std::string>::const_iterator sig=listofsignals.begin(); sig!=listofsignals.end(); ++sig) {
|
for (std::map<int, std::string>::const_iterator sig=listofsignals.begin(); sig!=listofsignals.end(); ++sig) {
|
||||||
sigaction(sig->first, &act, NULL);
|
sigaction(sig->first, &act, nullptr);
|
||||||
}
|
}
|
||||||
return check_internal(cppcheck, argc, argv);
|
return check_internal(cppcheck, argc, argv);
|
||||||
#else
|
#else
|
||||||
|
@ -912,7 +912,7 @@ void CppCheckExecutor::reportProgress(const std::string &filename, const char st
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Report progress messages every 10 seconds
|
// Report progress messages every 10 seconds
|
||||||
const std::time_t time2 = std::time(NULL);
|
const std::time_t time2 = std::time(nullptr);
|
||||||
if (time2 >= (time1 + 10)) {
|
if (time2 >= (time1 + 10)) {
|
||||||
time1 = time2;
|
time1 = time2;
|
||||||
|
|
||||||
|
|
|
@ -176,11 +176,11 @@ std::string FileLister::getAbsolutePath(const std::string& path)
|
||||||
|
|
||||||
#ifdef PATH_MAX
|
#ifdef PATH_MAX
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
if (realpath(path.c_str(), buf) != NULL)
|
if (realpath(path.c_str(), buf) != nullptr)
|
||||||
absolute_path = buf;
|
absolute_path = buf;
|
||||||
#else
|
#else
|
||||||
char *dynamic_buf;
|
char *dynamic_buf;
|
||||||
if ((dynamic_buf = realpath(path.c_str(), NULL)) != NULL) {
|
if ((dynamic_buf = realpath(path.c_str(), nullptr)) != nullptr) {
|
||||||
absolute_path = dynamic_buf;
|
absolute_path = dynamic_buf;
|
||||||
free(dynamic_buf);
|
free(dynamic_buf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
CppCheckExecutor exec;
|
CppCheckExecutor exec;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
GetModuleFileNameA(NULL, exename, sizeof(exename)/sizeof(exename[0])-1);
|
GetModuleFileNameA(nullptr, exename, sizeof(exename)/sizeof(exename[0])-1);
|
||||||
argv[0] = exename;
|
argv[0] = exename;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -238,7 +238,7 @@ unsigned int ThreadExecutor::check()
|
||||||
struct timeval tv; // for every second polling of load average condition
|
struct timeval tv; // for every second polling of load average condition
|
||||||
tv.tv_sec = 1;
|
tv.tv_sec = 1;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
int r = select(*std::max_element(rpipes.begin(), rpipes.end()) + 1, &rfds, NULL, NULL, &tv);
|
int r = select(*std::max_element(rpipes.begin(), rpipes.end()) + 1, &rfds, nullptr, nullptr, &tv);
|
||||||
|
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
std::list<int>::iterator rp = rpipes.begin();
|
std::list<int>::iterator rp = rpipes.begin();
|
||||||
|
|
|
@ -1847,7 +1847,7 @@ bool CheckClass::isConstMemberFunc(const Scope *scope, const Token *tok) const
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
// The container contains the STL types whose operator[] is not a const.
|
// The container contains the STL types whose operator[] is not a const.
|
||||||
static const std::set<std::string> stl_containers_not_const = make_container< std::set<std::string> >() << "map" << "unordered_map";
|
const std::set<std::string> stl_containers_not_const = make_container< std::set<std::string> >() << "map" << "unordered_map";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool& memberAccessed) const
|
bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool& memberAccessed) const
|
||||||
|
|
|
@ -95,8 +95,8 @@ struct Filepointer {
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static const std::set<std::string> whitelist = make_container< std::set<std::string> > ()
|
const std::set<std::string> whitelist = make_container< std::set<std::string> > ()
|
||||||
<< "clearerr" << "feof" << "ferror" << "fgetpos" << "ftell" << "setbuf" << "setvbuf" << "ungetc" << "ungetwc";
|
<< "clearerr" << "feof" << "ferror" << "fgetpos" << "ftell" << "setbuf" << "setvbuf" << "ungetc" << "ungetwc";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckIO::checkFileUsage()
|
void CheckIO::checkFileUsage()
|
||||||
|
@ -1552,8 +1552,8 @@ CheckIO::ArgumentInfo::~ArgumentInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static const std::set<std::string> stl_vector = make_container< std::set<std::string> >() << "array" << "vector";
|
const std::set<std::string> stl_vector = make_container< std::set<std::string> >() << "array" << "vector";
|
||||||
static const std::set<std::string> stl_string = make_container< std::set<std::string> >() << "string" << "u16string" << "u32string" << "wstring";
|
const std::set<std::string> stl_string = make_container< std::set<std::string> >() << "string" << "u16string" << "u32string" << "wstring";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckIO::ArgumentInfo::isStdVectorOrString()
|
bool CheckIO::ArgumentInfo::isStdVectorOrString()
|
||||||
|
@ -1614,7 +1614,7 @@ bool CheckIO::ArgumentInfo::isStdVectorOrString()
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static const std::set<std::string> stl_container = make_container< std::set<std::string> >() <<
|
const std::set<std::string> stl_container = make_container< std::set<std::string> >() <<
|
||||||
"array" << "bitset" << "deque" << "forward_list" <<
|
"array" << "bitset" << "deque" << "forward_list" <<
|
||||||
"hash_map" << "hash_multimap" << "hash_set" <<
|
"hash_map" << "hash_multimap" << "hash_set" <<
|
||||||
"list" << "map" << "multimap" << "multiset" <<
|
"list" << "map" << "multimap" << "multiset" <<
|
||||||
|
|
|
@ -138,7 +138,7 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static const std::set<std::string> stl_stream = make_container< std::set<std::string> >() <<
|
const std::set<std::string> stl_stream = make_container< std::set<std::string> >() <<
|
||||||
"fstream" << "ifstream" << "iostream" << "istream" <<
|
"fstream" << "ifstream" << "iostream" << "istream" <<
|
||||||
"istringstream" << "ofstream" << "ostream" << "ostringstream" <<
|
"istringstream" << "ofstream" << "ostream" << "ostringstream" <<
|
||||||
"stringstream" << "wistringstream" << "wostringstream" << "wstringstream";
|
"stringstream" << "wistringstream" << "wostringstream" << "wstringstream";
|
||||||
|
@ -376,7 +376,7 @@ void CheckNullPointer::nullPointer()
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static const std::set<std::string> stl_istream = make_container< std::set<std::string> >() <<
|
const std::set<std::string> stl_istream = make_container< std::set<std::string> >() <<
|
||||||
"fstream" << "ifstream" << "iostream" << "istream" <<
|
"fstream" << "ifstream" << "iostream" << "istream" <<
|
||||||
"istringstream" << "stringstream" << "wistringstream" << "wstringstream";
|
"istringstream" << "stringstream" << "wistringstream" << "wstringstream";
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,17 +254,16 @@ namespace {
|
||||||
const std::set<std::string> algorithm1x1 = make_container< std::set<std::string> >() // func(begin1 << x << end1
|
const std::set<std::string> algorithm1x1 = make_container< std::set<std::string> >() // func(begin1 << x << end1
|
||||||
<< "inplace_merge" << "nth_element" << "partial_sort" << "rotate" << "rotate_copy";
|
<< "inplace_merge" << "nth_element" << "partial_sort" << "rotate" << "rotate_copy";
|
||||||
|
|
||||||
static const std::string iteratorBeginFuncPattern = "begin|cbegin|rbegin|crbegin";
|
const std::string iteratorBeginFuncPattern = "begin|cbegin|rbegin|crbegin";
|
||||||
static const std::string iteratorEndFuncPattern = "end|cend|rend|crend";
|
const std::string iteratorEndFuncPattern = "end|cend|rend|crend";
|
||||||
|
|
||||||
static const std::string pattern1x1_1 = "%name% . " + iteratorBeginFuncPattern + " ( ) , ";
|
const std::string pattern1x1_1 = "%name% . " + iteratorBeginFuncPattern + " ( ) , ";
|
||||||
static const std::string pattern1x1_2 = "%name% . " + iteratorEndFuncPattern + " ( ) ,|)";
|
const std::string pattern1x1_2 = "%name% . " + iteratorEndFuncPattern + " ( ) ,|)";
|
||||||
static const std::string pattern2 = pattern1x1_1 + pattern1x1_2;
|
const std::string pattern2 = pattern1x1_1 + pattern1x1_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckStl::mismatchingContainers()
|
void CheckStl::mismatchingContainers()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Check if different containers are used in various calls of standard functions
|
// Check if different containers are used in various calls of standard functions
|
||||||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
const std::size_t functions = symbolDatabase->functionScopes.size();
|
||||||
|
@ -593,8 +592,6 @@ void CheckStl::invalidPointerError(const Token *tok, const std::string &func, co
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CheckStl::stlBoundaries()
|
void CheckStl::stlBoundaries()
|
||||||
{
|
{
|
||||||
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
|
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
|
@ -924,7 +921,7 @@ static bool isLocal(const Token *tok)
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static const std::set<std::string> stl_string_stream = make_container< std::set<std::string> >() <<
|
const std::set<std::string> stl_string_stream = make_container< std::set<std::string> >() <<
|
||||||
"istringstream" << "ostringstream" << "stringstream" << "wstringstream" ;
|
"istringstream" << "ostringstream" << "stringstream" << "wstringstream" ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1115,7 +1112,7 @@ void CheckStl::checkAutoPointer()
|
||||||
{
|
{
|
||||||
std::set<unsigned int> autoPtrVarId;
|
std::set<unsigned int> autoPtrVarId;
|
||||||
std::map<unsigned int, const std::string> mallocVarId; // variables allocated by the malloc-like function
|
std::map<unsigned int, const std::string> mallocVarId; // variables allocated by the malloc-like function
|
||||||
static const char STL_CONTAINER_LIST[] = "array|bitset|deque|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|vector|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset|basic_string";
|
const char STL_CONTAINER_LIST[] = "array|bitset|deque|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|vector|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset|basic_string";
|
||||||
const int malloc = _settings->library.alloc("malloc"); // allocation function, which are not compatible with auto_ptr
|
const int malloc = _settings->library.alloc("malloc"); // allocation function, which are not compatible with auto_ptr
|
||||||
const bool printStyle = _settings->isEnabled("style");
|
const bool printStyle = _settings->isEnabled("style");
|
||||||
|
|
||||||
|
@ -1229,7 +1226,7 @@ void CheckStl::autoPointerMallocError(const Token *tok, const std::string& alloc
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static const std::set<std::string> stl_containers_with_empty_and_clear = make_container< std::set<std::string> >() <<
|
const std::set<std::string> stl_containers_with_empty_and_clear = make_container< std::set<std::string> >() <<
|
||||||
"deque" << "forward_list" << "list" <<
|
"deque" << "forward_list" << "list" <<
|
||||||
"map" << "multimap" << "multiset" << "set" << "string" <<
|
"map" << "multimap" << "multiset" << "set" << "string" <<
|
||||||
"unordered_map" << "unordered_multimap" << "unordered_multiset" <<
|
"unordered_map" << "unordered_multimap" << "unordered_multiset" <<
|
||||||
|
@ -1389,7 +1386,6 @@ void CheckStl::dereferenceInvalidIteratorError(const Token* deref, const std::st
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CheckStl::readingEmptyStlContainer_parseUsage(const Token* tok, const Library::Container* container, std::map<unsigned int, const Library::Container*>& empty, bool noerror)
|
void CheckStl::readingEmptyStlContainer_parseUsage(const Token* tok, const Library::Container* container, std::map<unsigned int, const Library::Container*>& empty, bool noerror)
|
||||||
{
|
{
|
||||||
// Check for various conditions for the way stl containers and variables can be used
|
// Check for various conditions for the way stl containers and variables can be used
|
||||||
|
|
|
@ -1067,12 +1067,12 @@ bool CheckUninitVar::isMemberVariableAssignment(const Token *tok, const std::str
|
||||||
}
|
}
|
||||||
|
|
||||||
// is this a function call?
|
// is this a function call?
|
||||||
ftok = ftok ? ftok->previous() : NULL;
|
ftok = ftok ? ftok->previous() : nullptr;
|
||||||
if (Token::Match(ftok, "%name% (")) {
|
if (Token::Match(ftok, "%name% (")) {
|
||||||
// check how function handle uninitialized data arguments..
|
// check how function handle uninitialized data arguments..
|
||||||
const Function *function = ftok->function();
|
const Function *function = ftok->function();
|
||||||
const Variable *arg = function ? function->getArgumentVar(argumentNumber) : NULL;
|
const Variable *arg = function ? function->getArgumentVar(argumentNumber) : nullptr;
|
||||||
const Token *argStart = arg ? arg->typeStartToken() : NULL;
|
const Token *argStart = arg ? arg->typeStartToken() : nullptr;
|
||||||
while (argStart && argStart->previous() && argStart->previous()->isName())
|
while (argStart && argStart->previous() && argStart->previous()->isName())
|
||||||
argStart = argStart->previous();
|
argStart = argStart->previous();
|
||||||
if (Token::Match(argStart, "const struct| %type% * const| %name% [,)]"))
|
if (Token::Match(argStart, "const struct| %type% * const| %name% [,)]"))
|
||||||
|
|
|
@ -249,7 +249,7 @@ std::string Path::getAbsoluteFilePath(const std::string& filePath)
|
||||||
if (_fullpath(absolute, filePath.c_str(), _MAX_PATH))
|
if (_fullpath(absolute, filePath.c_str(), _MAX_PATH))
|
||||||
absolute_path = absolute;
|
absolute_path = absolute;
|
||||||
#elif defined(__linux__) || defined(__sun) || defined(__hpux) || defined(__GNUC__)
|
#elif defined(__linux__) || defined(__sun) || defined(__hpux) || defined(__GNUC__)
|
||||||
char * absolute = realpath(filePath.c_str(), NULL);
|
char * absolute = realpath(filePath.c_str(), nullptr);
|
||||||
if (absolute)
|
if (absolute)
|
||||||
absolute_path = absolute;
|
absolute_path = absolute;
|
||||||
free(absolute);
|
free(absolute);
|
||||||
|
|
|
@ -2658,6 +2658,15 @@ static void setVarIdClassFunction(const std::string &classname,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// Variable declarations can't start with "return" etc.
|
||||||
|
const std::set<std::string> notstart_c = make_container< std::set<std::string> > ()
|
||||||
|
<< "goto" << "NOT" << "return" << "sizeof"<< "typedef";
|
||||||
|
const std::set<std::string> notstart_cpp = make_container< std::set<std::string> > ()
|
||||||
|
<< notstart_c
|
||||||
|
<< "delete" << "friend" << "new" << "throw" << "using" << "virtual" << "explicit" << "const_cast" << "dynamic_cast" << "reinterpret_cast" << "static_cast" ;
|
||||||
|
}
|
||||||
|
|
||||||
void Tokenizer::setVarId()
|
void Tokenizer::setVarId()
|
||||||
{
|
{
|
||||||
// Clear all variable ids
|
// Clear all variable ids
|
||||||
|
@ -2669,16 +2678,7 @@ void Tokenizer::setVarId()
|
||||||
setPodTypes();
|
setPodTypes();
|
||||||
|
|
||||||
// Variable declarations can't start with "return" etc.
|
// Variable declarations can't start with "return" etc.
|
||||||
std::set<std::string> notstart;
|
const std::set<std::string>& notstart = (isC()) ? notstart_c : notstart_cpp;
|
||||||
notstart.insert("goto");
|
|
||||||
notstart.insert("NOT");
|
|
||||||
notstart.insert("return");
|
|
||||||
notstart.insert("sizeof");
|
|
||||||
notstart.insert("typedef");
|
|
||||||
if (!isC()) {
|
|
||||||
static const char *str[] = {"delete","friend","new","throw","using","virtual","explicit","const_cast","dynamic_cast","reinterpret_cast","static_cast"};
|
|
||||||
notstart.insert(str, str+(sizeof(str)/sizeof(*str)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// variable id
|
// variable id
|
||||||
_varId = 0;
|
_varId = 0;
|
||||||
|
|
|
@ -733,7 +733,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
maxconfigs = true;
|
maxconfigs = true;
|
||||||
} else if (settings.filename==NULL && strchr(argv[i],'.'))
|
} else if (settings.filename==nullptr && strchr(argv[i],'.'))
|
||||||
settings.filename = argv[i];
|
settings.filename = argv[i];
|
||||||
else if (settings.linenr == 0U && MathLib::isInt(argv[i]))
|
else if (settings.linenr == 0U && MathLib::isInt(argv[i]))
|
||||||
settings.linenr = std::atoi(argv[i]);
|
settings.linenr = std::atoi(argv[i]);
|
||||||
|
@ -749,7 +749,7 @@ int main(int argc, char *argv[])
|
||||||
if (settings._force)
|
if (settings._force)
|
||||||
settings._maxConfigs = ~0U;
|
settings._maxConfigs = ~0U;
|
||||||
|
|
||||||
if ((!settings.hang && settings.linenr == 0U) || settings.filename == NULL) {
|
if ((!settings.hang && settings.linenr == 0U) || settings.filename == nullptr) {
|
||||||
std::cerr << "Syntax:" << std::endl
|
std::cerr << "Syntax:" << std::endl
|
||||||
<< argv[0] << " [--stdout] [--cfg=X] [--hang] [--maxtime=60] [-D define] [-I includepath] [--force] [--enable=<id>] [--inconclusive] [--debug-warnings] [--max-configs=<limit>] filename [linenr]" << std::endl;
|
<< argv[0] << " [--stdout] [--cfg=X] [--hang] [--maxtime=60] [-D define] [-I includepath] [--force] [--enable=<id>] [--inconclusive] [--debug-warnings] [--max-configs=<limit>] filename [linenr]" << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
Loading…
Reference in New Issue