Small refactoring: replace NULL by nullptr, remove redundant static keyword, Tokenizer::setVarId() uses const variable 'notstart'

This commit is contained in:
Alexander Mai 2015-11-30 22:13:49 +01:00
parent 9a42f52915
commit f762affea0
12 changed files with 41 additions and 45 deletions

View File

@ -580,10 +580,10 @@ namespace {
hThread,
&stack,
&context,
NULL,
nullptr,
pSymFunctionTableAccess64,
pSymGetModuleBase64,
NULL
nullptr
);
if (!result) // official end...
break;
@ -748,7 +748,7 @@ int CppCheckExecutor::check_wrapper(CppCheck& cppcheck, int argc, const char* co
segv_stack.ss_sp = mytstack;
segv_stack.ss_flags = 0;
segv_stack.ss_size = MYSTACKSIZE;
sigaltstack(&segv_stack, NULL);
sigaltstack(&segv_stack, nullptr);
// install signal handler
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_sigaction=CppcheckSignalHandler;
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);
#else
@ -912,7 +912,7 @@ void CppCheckExecutor::reportProgress(const std::string &filename, const char st
return;
// 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)) {
time1 = time2;

View File

@ -176,11 +176,11 @@ std::string FileLister::getAbsolutePath(const std::string& path)
#ifdef PATH_MAX
char buf[PATH_MAX];
if (realpath(path.c_str(), buf) != NULL)
if (realpath(path.c_str(), buf) != nullptr)
absolute_path = buf;
#else
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;
free(dynamic_buf);
}

View File

@ -126,7 +126,7 @@ int main(int argc, char* argv[])
CppCheckExecutor exec;
#ifdef _WIN32
GetModuleFileNameA(NULL, exename, sizeof(exename)/sizeof(exename[0])-1);
GetModuleFileNameA(nullptr, exename, sizeof(exename)/sizeof(exename[0])-1);
argv[0] = exename;
#endif

View File

@ -238,7 +238,7 @@ unsigned int ThreadExecutor::check()
struct timeval tv; // for every second polling of load average condition
tv.tv_sec = 1;
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) {
std::list<int>::iterator rp = rpipes.begin();

View File

@ -1847,7 +1847,7 @@ bool CheckClass::isConstMemberFunc(const Scope *scope, const Token *tok) const
namespace {
// 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

View File

@ -95,8 +95,8 @@ struct Filepointer {
};
namespace {
static const std::set<std::string> whitelist = make_container< std::set<std::string> > ()
<< "clearerr" << "feof" << "ferror" << "fgetpos" << "ftell" << "setbuf" << "setvbuf" << "ungetc" << "ungetwc";
const std::set<std::string> whitelist = make_container< std::set<std::string> > ()
<< "clearerr" << "feof" << "ferror" << "fgetpos" << "ftell" << "setbuf" << "setvbuf" << "ungetc" << "ungetwc";
}
void CheckIO::checkFileUsage()
@ -1552,8 +1552,8 @@ CheckIO::ArgumentInfo::~ArgumentInfo()
}
namespace {
static 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_vector = make_container< std::set<std::string> >() << "array" << "vector";
const std::set<std::string> stl_string = make_container< std::set<std::string> >() << "string" << "u16string" << "u32string" << "wstring";
}
bool CheckIO::ArgumentInfo::isStdVectorOrString()
@ -1614,7 +1614,7 @@ bool CheckIO::ArgumentInfo::isStdVectorOrString()
}
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" <<
"hash_map" << "hash_multimap" << "hash_set" <<
"list" << "map" << "multimap" << "multiset" <<

View File

@ -138,7 +138,7 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
}
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" <<
"istringstream" << "ofstream" << "ostream" << "ostringstream" <<
"stringstream" << "wistringstream" << "wostringstream" << "wstringstream";
@ -376,7 +376,7 @@ void CheckNullPointer::nullPointer()
}
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" <<
"istringstream" << "stringstream" << "wistringstream" << "wstringstream";
}

View File

@ -254,17 +254,16 @@ namespace {
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";
static const std::string iteratorBeginFuncPattern = "begin|cbegin|rbegin|crbegin";
static const std::string iteratorEndFuncPattern = "end|cend|rend|crend";
const std::string iteratorBeginFuncPattern = "begin|cbegin|rbegin|crbegin";
const std::string iteratorEndFuncPattern = "end|cend|rend|crend";
static const std::string pattern1x1_1 = "%name% . " + iteratorBeginFuncPattern + " ( ) , ";
static const std::string pattern1x1_2 = "%name% . " + iteratorEndFuncPattern + " ( ) ,|)";
static const std::string pattern2 = pattern1x1_1 + pattern1x1_2;
const std::string pattern1x1_1 = "%name% . " + iteratorBeginFuncPattern + " ( ) , ";
const std::string pattern1x1_2 = "%name% . " + iteratorEndFuncPattern + " ( ) ,|)";
const std::string pattern2 = pattern1x1_1 + pattern1x1_2;
}
void CheckStl::mismatchingContainers()
{
// Check if different containers are used in various calls of standard functions
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
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()
{
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
@ -924,7 +921,7 @@ static bool isLocal(const Token *tok)
}
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" ;
}
@ -1115,7 +1112,7 @@ void CheckStl::checkAutoPointer()
{
std::set<unsigned int> autoPtrVarId;
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 bool printStyle = _settings->isEnabled("style");
@ -1229,7 +1226,7 @@ void CheckStl::autoPointerMallocError(const Token *tok, const std::string& alloc
}
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" <<
"map" << "multimap" << "multiset" << "set" << "string" <<
"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)
{
// Check for various conditions for the way stl containers and variables can be used

View File

@ -1067,12 +1067,12 @@ bool CheckUninitVar::isMemberVariableAssignment(const Token *tok, const std::str
}
// is this a function call?
ftok = ftok ? ftok->previous() : NULL;
ftok = ftok ? ftok->previous() : nullptr;
if (Token::Match(ftok, "%name% (")) {
// check how function handle uninitialized data arguments..
const Function *function = ftok->function();
const Variable *arg = function ? function->getArgumentVar(argumentNumber) : NULL;
const Token *argStart = arg ? arg->typeStartToken() : NULL;
const Variable *arg = function ? function->getArgumentVar(argumentNumber) : nullptr;
const Token *argStart = arg ? arg->typeStartToken() : nullptr;
while (argStart && argStart->previous() && argStart->previous()->isName())
argStart = argStart->previous();
if (Token::Match(argStart, "const struct| %type% * const| %name% [,)]"))

View File

@ -249,7 +249,7 @@ std::string Path::getAbsoluteFilePath(const std::string& filePath)
if (_fullpath(absolute, filePath.c_str(), _MAX_PATH))
absolute_path = absolute;
#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)
absolute_path = absolute;
free(absolute);

View File

@ -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()
{
// Clear all variable ids
@ -2669,16 +2678,7 @@ void Tokenizer::setVarId()
setPodTypes();
// Variable declarations can't start with "return" etc.
std::set<std::string> notstart;
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)));
}
const std::set<std::string>& notstart = (isC()) ? notstart_c : notstart_cpp;
// variable id
_varId = 0;

View File

@ -733,7 +733,7 @@ int main(int argc, char *argv[])
}
maxconfigs = true;
} else if (settings.filename==NULL && strchr(argv[i],'.'))
} else if (settings.filename==nullptr && strchr(argv[i],'.'))
settings.filename = argv[i];
else if (settings.linenr == 0U && MathLib::isInt(argv[i]))
settings.linenr = std::atoi(argv[i]);
@ -749,7 +749,7 @@ int main(int argc, char *argv[])
if (settings._force)
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
<< 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;