Change some more 0 literals into nullptr.

This commit is contained in:
Lauri Nurmi 2014-02-16 12:47:52 +02:00
parent 23efc68dd7
commit 70a67eaf85
21 changed files with 71 additions and 71 deletions

View File

@ -79,7 +79,7 @@ void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const Arra
errmsg << " out of bounds.";
}
const Token *condition = 0;
const Token *condition = nullptr;
for (unsigned int i = 0; i < index.size(); ++i) {
if (condition == nullptr)
condition = index[i].condition;
@ -428,7 +428,7 @@ static bool for3(const Token * const tok,
std::string &max_value,
const bool maxMinFlipped)
{
assert(tok != 0);
assert(tok != nullptr);
if (Token::Match(tok, "%varid% = %num% + %varid% )", varid)) {
if (!for_maxvalue(tok->tokAt(2), min_value, max_value))
return false;
@ -1498,7 +1498,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
std::string type;
// varid : The variable id for the array
const Variable *var = 0;
const Variable *var = nullptr;
// nextTok : number of tokens used in variable declaration - used to skip to next statement.
int nextTok = 0;

View File

@ -917,8 +917,8 @@ void CheckClass::checkMemset()
continue;
const Token *typeTok = 0;
const Scope *type = 0;
const Token *typeTok = nullptr;
const Scope *type = nullptr;
if (Token::Match(arg3, "sizeof ( %type% ) )"))
typeTok = arg3->tokAt(2);
else if (Token::Match(arg3, "sizeof ( %type% :: %type% ) )"))
@ -1252,7 +1252,7 @@ bool CheckClass::hasAllocation(const Function *func, const Scope* scope)
return true;
// check for deallocating memory
const Token *var = 0;
const Token *var = nullptr;
if (Token::Match(tok, "free ( %var%"))
var = tok->tokAt(2);
else if (Token::Match(tok, "delete [ ] %var%"))
@ -1395,7 +1395,7 @@ void CheckClass::virtualDestructor()
// Find the destructor declaration for the base class.
const Function *base_destructor = derivedFromScope->getDestructor();
const Token *base = 0;
const Token *base = nullptr;
if (base_destructor)
base = base_destructor->token;

View File

@ -98,7 +98,7 @@ void CheckExceptionSafety::deallocThrow()
const unsigned int varid(tok->varId());
// Token where throw occurs
const Token *ThrowToken = 0;
const Token *ThrowToken = nullptr;
// is there a throw after the deallocation?
const Token* const end2 = tok->scope()->classEnd;

View File

@ -318,7 +318,7 @@ void CheckIO::invalidScanf()
for (std::size_t j = 0; j < functions; ++j) {
const Scope * scope = symbolDatabase->functionScopes[j];
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
const Token *formatToken = 0;
const Token *formatToken = nullptr;
if (Token::Match(tok, "scanf|vscanf ( %str% ,"))
formatToken = tok->tokAt(2);
else if (Token::Match(tok, "sscanf|vsscanf|fscanf|vfscanf (")) {
@ -424,7 +424,7 @@ static bool findFormat(unsigned int arg, const Token *firstArg,
argTok->variable()->dimensionKnown(0) &&
argTok->variable()->dimension(0) != 0)))) {
*formatArgTok = argTok->nextArgument();
*formatStringTok = 0;
*formatStringTok = nullptr;
if (argTok->variable()) {
const Token *varTok = argTok->variable()->nameToken();
if (Token::Match(varTok, "%var% ; %var% = %str% ;") &&
@ -1330,7 +1330,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings)
tok = tok->tokAt(2);
if (!tok || !(tok->type() == Token::eVariable || tok->type() == Token::eFunction))
return;
const Token *varTok = 0;
const Token *varTok = nullptr;
const Token *tok1 = tok->next();
for (; tok1; tok1 = tok1->next()) {
if (tok1->str() == "," || tok1->str() == ")") {

View File

@ -629,7 +629,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
Token *ftok = getcode(func->functionScope->classStart->next(), callstack, 0, alloctype, dealloctype, false, 1);
simplifycode(ftok);
const char *ret = 0;
const char *ret = nullptr;
if (Token::simpleMatch(ftok, "; alloc ; }"))
ret = "alloc";
else if (Token::simpleMatch(ftok, "; dealloc ; }"))
@ -688,7 +688,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
while (func_ && func_->str() == ";")
func_ = func_->next();
const char *ret = 0;
const char *ret = nullptr;
/** @todo handle "goto" */
if (Token::findsimplematch(func_, "dealloc"))
ret = "dealloc";
@ -782,7 +782,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
;
else {
const Token *skipToToken = 0;
const Token *skipToToken = nullptr;
// scan statement for interesting keywords / varid
for (tok2 = tok->next(); tok2; tok2 = tok2->next()) {

View File

@ -629,8 +629,8 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
continue;
// vartok : token for the variable
const Token *vartok = 0;
const Token *checkConditionStart = 0;
const Token *vartok = nullptr;
const Token *checkConditionStart = nullptr;
if (Token::Match(tok, "( ! %var% )|&&")) {
vartok = tok->tokAt(2);
checkConditionStart = vartok->next();
@ -892,7 +892,7 @@ void CheckNullPointer::nullConstantDereference()
}
}
const Variable *ovar = 0;
const Variable *ovar = nullptr;
if (Token::Match(tok, "0 ==|!= %var% !!."))
ovar = tok->tokAt(2)->variable();
else if (Token::Match(tok, "%var% ==|!= 0"))

View File

@ -514,7 +514,7 @@ void CheckOther::invalidPointerCast()
continue;
// Find casted variable
const Variable *var = 0;
const Variable *var = nullptr;
bool allocation = false;
bool ref = false;
if (Token::Match(nextTok, "new %type%"))

View File

@ -113,7 +113,7 @@ void CheckSizeof::checkSizeofForPointerSize()
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
const Token *tokVar;
const Token *variable;
const Token *variable2 = 0;
const Token *variable2 = nullptr;
// Find any function that may use sizeof on a pointer
// Once leaving those tests, it is mandatory to have:

View File

@ -655,7 +655,7 @@ void CheckStl::pushback()
if (varId == 0)
continue;
const Token *pushbackTok = 0;
const Token *pushbackTok = nullptr;
// Count { and } for tok3
const Token *tok3 = tok2->tokAt(20);
@ -1077,7 +1077,7 @@ void CheckStl::missingComparison()
break;
}
const Token *incrementToken = 0;
const Token *incrementToken = nullptr;
// Parse loop..
for (const Token *tok3 = i->classStart; tok3 != i->classEnd; tok3 = tok3->next()) {

View File

@ -51,7 +51,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
if (tok->previous() && tok->previous()->str() == ">")
continue;
const Token *funcname = 0;
const Token *funcname = nullptr;
if (Token::Match(tok, "%type% %var% ("))
funcname = tok->next();
@ -188,7 +188,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
}
const Token *funcname = 0;
const Token *funcname = nullptr;
if (Token::Match(tok->next(), "%var% (")) {
funcname = tok->next();

View File

@ -40,7 +40,7 @@ public:
/** Store information about variable usage */
class VariableUsage {
public:
VariableUsage(const Variable *var = 0,
VariableUsage(const Variable *var = nullptr,
VariableType type = standard,
bool read = false,
bool write = false,

View File

@ -449,7 +449,7 @@ void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &token
if (rule.pattern.empty() || rule.id.empty() || rule.severity.empty() || rule.tokenlist != tokenlist)
continue;
const char *error = 0;
const char *error = nullptr;
int erroffset = 0;
pcre *re = pcre_compile(rule.pattern.c_str(),0,&error,&erroffset,nullptr);
if (!re) {

View File

@ -54,7 +54,7 @@ public:
/** character that is inserted in expanded macros */
static char macroChar;
Preprocessor(Settings *settings = 0, ErrorLogger *errorLogger = 0);
Preprocessor(Settings *settings = nullptr, ErrorLogger *errorLogger = nullptr);
static bool missingIncludeFlag;

View File

@ -310,8 +310,8 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
// check if in class or structure
else if (scope->type == Scope::eClass || scope->type == Scope::eStruct) {
const Token *funcStart = 0;
const Token *argStart = 0;
const Token *funcStart = nullptr;
const Token *argStart = nullptr;
// What section are we in..
if (tok->str() == "private:")
@ -558,8 +558,8 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
scope->definedType->friendList.push_back(friendInfo);
}
} else if (scope->type == Scope::eNamespace || scope->type == Scope::eGlobal) {
const Token *funcStart = 0;
const Token *argStart = 0;
const Token *funcStart = nullptr;
const Token *argStart = nullptr;
// function?
if (isFunction(tok, scope, &funcStart, &argStart)) {
@ -2723,7 +2723,7 @@ bool SymbolDatabase::isCPP() const
const Scope *SymbolDatabase::findScope(const Token *tok, const Scope *startScope) const
{
const Scope *scope = 0;
const Scope *scope = nullptr;
// absolute path
if (tok->str() == "::") {
tok = tok->next();

View File

@ -846,7 +846,7 @@ Token* Token::nextArgument() const
const Token * Token::findClosingBracket() const
{
const Token *closing = 0;
const Token *closing = nullptr;
if (_str == "<") {
unsigned int depth = 0;

View File

@ -382,7 +382,7 @@ public:
* @param title Title for the printout or use default parameter or 0
* for no title.
*/
void printOut(const char *title = 0) const;
void printOut(const char *title = nullptr) const;
/**
* For debugging purposes, prints token and all tokens
@ -591,7 +591,7 @@ public:
}
const ValueFlow::Value * getMaxValue(bool condition) const {
const ValueFlow::Value *ret = 0;
const ValueFlow::Value *ret = nullptr;
std::list<ValueFlow::Value>::const_iterator it;
for (it = values.begin(); it != values.end(); ++it) {
if ((!ret || it->intvalue > ret->intvalue) &&

View File

@ -603,19 +603,19 @@ void Tokenizer::simplifyTypedef()
Token *typeName;
std::list<std::string> pointers;
Token *typeStart = 0;
Token *typeEnd = 0;
Token *argStart = 0;
Token *argEnd = 0;
Token *arrayStart = 0;
Token *arrayEnd = 0;
Token *specStart = 0;
Token *specEnd = 0;
Token *typeStart = nullptr;
Token *typeEnd = nullptr;
Token *argStart = nullptr;
Token *argEnd = nullptr;
Token *arrayStart = nullptr;
Token *arrayEnd = nullptr;
Token *specStart = nullptr;
Token *specEnd = nullptr;
Token *typeDef = tok;
Token *argFuncRetStart = 0;
Token *argFuncRetEnd = 0;
Token *funcStart = 0;
Token *funcEnd = 0;
Token *argFuncRetStart = nullptr;
Token *argFuncRetEnd = nullptr;
Token *funcStart = nullptr;
Token *funcEnd = nullptr;
Token *tokOffset = tok->next();
bool function = false;
bool functionPtr = false;
@ -626,8 +626,8 @@ void Tokenizer::simplifyTypedef()
bool refToArray = false;
bool ptrMember = false;
bool typeOf = false;
Token *namespaceStart = 0;
Token *namespaceEnd = 0;
Token *namespaceStart = nullptr;
Token *namespaceEnd = nullptr;
// check for invalid input
if (!tok->next()) {
@ -4440,7 +4440,7 @@ void Tokenizer::simplifyConditionOperator()
else
tok->deleteNext(8);
Token *starttok = 0;
Token *starttok = nullptr;
std::string str;
if (isReturn)
@ -7347,9 +7347,9 @@ void Tokenizer::simplifyEnum()
(!temp->isName() || !Token::Match(temp->next(), "[{:;]")))
continue;
Token *start = tok;
Token *enumType = 0;
Token *typeTokenStart = 0;
Token *typeTokenEnd = 0;
Token *enumType = nullptr;
Token *typeTokenStart = nullptr;
Token *typeTokenEnd = nullptr;
// check for C++0x enum class
if (Token::Match(tok->next(), "class|struct"))
@ -7965,7 +7965,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
std::vector<unsigned int> switchindents;
bool checklabel = false;
Token *tok = begin;
Token *tokcheck = 0;
Token *tokcheck = nullptr;
while (tok->next() && tok->next() != end) {
if (tok->next()->str() == "(") {
++roundbraces;
@ -8639,11 +8639,11 @@ void Tokenizer::removeExceptionSpecifications()
bool Tokenizer::validate() const
{
std::stack<const Token *> linktok;
const Token *lastTok = 0;
const Token *lastTok = nullptr;
for (const Token *tok = tokens(); tok; tok = tok->next()) {
lastTok = tok;
if (Token::Match(tok, "[{([]") || (tok->str() == "<" && tok->link())) {
if (tok->link() == 0) {
if (tok->link() == nullptr) {
cppcheckError(tok);
return false;
}
@ -8652,7 +8652,7 @@ bool Tokenizer::validate() const
}
else if (Token::Match(tok, "[})]]") || (tok->str() == ">" && tok->link())) {
if (tok->link() == 0) {
if (tok->link() == nullptr) {
cppcheckError(tok);
return false;
}
@ -8675,7 +8675,7 @@ bool Tokenizer::validate() const
linktok.pop();
}
else if (tok->link() != 0) {
else if (tok->link() != nullptr) {
cppcheckError(tok);
return false;
}
@ -8867,7 +8867,7 @@ void Tokenizer::simplifyErrNoInWhile()
if (tok->str() != "errno")
continue;
Token *endpar = 0;
Token *endpar = nullptr;
if (Token::Match(tok->previous(), "&& errno == EINTR ) { ;| }"))
endpar = tok->tokAt(3);
else if (Token::Match(tok->tokAt(-2), "&& ( errno == EINTR ) ) { ;| }"))
@ -9018,7 +9018,7 @@ void Tokenizer::simplifyStructDecl()
}
if (!Token::simpleMatch(tok2, "} ;"))
continue;
Token *vartok = 0;
Token *vartok = nullptr;
tok2 = tok1->tokAt(2);
while (Token::Match(tok2, "%type% %var% ;")) {
if (!vartok) {
@ -9295,7 +9295,7 @@ void Tokenizer::simplifyBitfields()
goback = false;
tok = tok->previous();
}
Token *last = 0;
Token *last = nullptr;
if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% %var% :") &&
!Token::Match(tok->next(), "case|public|protected|private|class|struct") &&

View File

@ -63,7 +63,7 @@ public:
* \param unknown set to true if it's unknown if the scope is noreturn
* \return true if scope ends with a function call that might be 'noreturn'
*/
bool IsScopeNoReturn(const Token *endScopeToken, bool *unknown = 0) const;
bool IsScopeNoReturn(const Token *endScopeToken, bool *unknown = nullptr) const;
/**
* Tokenize code

View File

@ -698,7 +698,7 @@ static Token * createAstAtToken(Token *tok)
{
if (Token::simpleMatch(tok,"for (")) {
Token *tok2 = tok->tokAt(2);
Token *init1 = 0;
Token *init1 = nullptr;
const Token * const endPar = tok->next()->link();
while (tok2 && tok2 != endPar && tok2->str() != ";") {
if (tok2->str() == "<" && tok2->link()) {

View File

@ -608,7 +608,7 @@ static void valueFlowForLoop(TokenList *tokenlist, ErrorLogger *errorLogger, con
if (vartok->varId() == 0U)
continue;
tok = vartok->tokAt(4);
const Token *num2tok = 0;
const Token *num2tok = nullptr;
if (Token::Match(tok, "%varid% <|<=|!=", vartok->varId())) {
tok = tok->next();
num2tok = tok->astOperand2();

View File

@ -836,7 +836,7 @@ private:
void hasSubClassConstructor() {
GET_SYMBOL_DB("class Foo { class Sub; }; class Foo::Sub { Sub() {} };");
ASSERT(db != 0);
ASSERT(db != nullptr);
if (db) {
bool seen_something = false;
@ -930,11 +930,11 @@ private:
ASSERT(db && db->scopeList.size() == 4);
if (db) {
const Scope* foo = db->findScopeByName("Foo");
ASSERT(foo != 0);
ASSERT(foo != nullptr);
const Scope* bar1 = db->findScopeByName("Bar1");
ASSERT(bar1 != 0);
ASSERT(bar1 != nullptr);
const Scope* bar2 = db->findScopeByName("Bar2");
ASSERT(bar2 != 0);
ASSERT(bar2 != nullptr);
if (foo && bar1 && bar2) {
ASSERT(bar1->definedType->friendList.size() == 1 && bar1->definedType->friendList.front().name == "Foo" && bar1->definedType->friendList.front().type == foo->definedType);
@ -1159,7 +1159,7 @@ private:
}
}
ASSERT(scope != 0);
ASSERT(scope != nullptr);
if (!scope)
return;
@ -1193,7 +1193,7 @@ private:
}
}
ASSERT(scope != 0);
ASSERT(scope != nullptr);
if (!scope)
return;
@ -1836,14 +1836,14 @@ private:
ASSERT_EQUALS("", errout.str());
if (db) {
const Scope * bar = db->findScopeByName("bar");
ASSERT(bar != 0);
ASSERT(bar != nullptr);
if (bar) {
unsigned int linenrs[] = { 2, 1 };
unsigned int index = 0;
for (const Token * tok = bar->classStart->next(); tok != bar->classEnd; tok = tok->next()) {
if (Token::Match(tok, "%var% (") && !tok->varId() && Token::simpleMatch(tok->linkAt(1), ") ;")) {
const Function * function = db->findFunction(tok);
ASSERT(function != 0);
ASSERT(function != nullptr);
if (function) {
std::stringstream expected;
expected << "Function call on line " << tok->linenr() << " calls function on line " << linenrs[index] << std::endl;