Use nullptr instead of 0 or NULL (#936)

This commit is contained in:
Ayaz Salikhov 2017-08-09 21:00:26 +03:00 committed by Daniel Marjamäki
parent c1b0a07ab3
commit b8cd7dbb5c
38 changed files with 169 additions and 169 deletions

View File

@ -78,7 +78,7 @@
/*static*/ FILE* CppCheckExecutor::exceptionOutput = stdout;
CppCheckExecutor::CppCheckExecutor()
: _settings(0), time1(0), errorOutput(nullptr), errorlist(false)
: _settings(nullptr), time1(0), errorOutput(nullptr), errorlist(false)
{
}
@ -823,7 +823,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
}
if (settings.reportProgress)
time1 = std::time(0);
time1 = std::time(nullptr);
if (!settings.outputFile.empty()) {
errorOutput = new std::ofstream(settings.outputFile);
@ -930,7 +930,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
reportErr(ErrorLogger::ErrorMessage::getXMLFooter());
}
_settings = 0;
_settings = nullptr;
if (returnValue)
return settings.exitCode;
else

View File

@ -188,7 +188,7 @@ static void addFiles2(std::map<std::string, std::size_t> &files,
std::string new_path;
new_path.reserve(path.length() + 100);// prealloc some memory to avoid constant new/deletes in loop
while ((readdir_r(dir, &entry, &dir_result) == 0) && (dir_result != NULL)) {
while ((readdir_r(dir, &entry, &dir_result) == 0) && (dir_result != nullptr)) {
if ((std::strcmp(dir_result->d_name, ".") == 0) ||
(std::strcmp(dir_result->d_name, "..") == 0))

View File

@ -25,7 +25,7 @@
//---------------------------------------------------------------------------
Check::Check(const std::string &aname)
: _tokenizer(0), _settings(0), _errorLogger(0), _name(aname)
: _tokenizer(nullptr), _settings(nullptr), _errorLogger(nullptr), _name(aname)
{
for (std::list<Check*>::iterator i = instances().begin(); i != instances().end(); ++i) {
if ((*i)->name() > aname) {

View File

@ -146,7 +146,7 @@ protected:
/** report an error */
template<typename T, typename U>
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const T id, const U msg, const CWE &cwe, bool inconclusive) {
const ErrorLogger::ErrorMessage errmsg(callstack, _tokenizer?&_tokenizer->list:0, severity, id, msg, cwe, inconclusive);
const ErrorLogger::ErrorMessage errmsg(callstack, _tokenizer ? &_tokenizer->list : nullptr, severity, id, msg, cwe, inconclusive);
if (_errorLogger)
_errorLogger->reportErr(errmsg);
else

View File

@ -52,7 +52,7 @@ void Check64BitPortability::pointerassignment()
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
if (scope->function == 0 || !scope->function->hasBody()) // We only look for functions with a body
if (scope->function == nullptr || !scope->function->hasBody()) // We only look for functions with a body
continue;
bool retPointer = false;

View File

@ -65,8 +65,8 @@ private:
void boostForeachError(const Token *tok);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckBoost c(0, settings, errorLogger);
c.boostForeachError(0);
CheckBoost c(nullptr, settings, errorLogger);
c.boostForeachError(nullptr);
}
static std::string myName() {

View File

@ -1299,7 +1299,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
continue;
}
if (var == 0)
if (var == nullptr)
continue;
const MathLib::bigint totalSize = size * static_cast<int>(sizeOfType(var->typeStartToken()));

View File

@ -504,7 +504,7 @@ bool CheckClass::isBaseClassFunc(const Token *tok, const Scope *scope)
void CheckClass::initializeVarList(const Function &func, std::list<const Function *> &callstack, const Scope *scope, std::vector<Usage> &usage)
{
if (!func.functionScope)
throw InternalError(0, "Internal Error: Invalid syntax"); // #5702
throw InternalError(nullptr, "Internal Error: Invalid syntax"); // #5702
bool initList = func.isConstructor();
const Token *ftok = func.arg->link()->next();
int level = 0;
@ -1022,7 +1022,7 @@ static const Scope* findFunctionOf(const Scope* scope)
return scope->functionOf;
scope = scope->nestedIn;
}
return 0;
return nullptr;
}
void CheckClass::checkMemset()
@ -1364,7 +1364,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
}
return;
}
if (_settings->library.isScopeNoReturn(last, 0)) {
if (_settings->library.isScopeNoReturn(last, nullptr)) {
// Typical wrong way to prohibit default assignment operator
// by always throwing an exception or calling a noreturn function
operatorEqShouldBeLeftUnimplementedError(func->token);
@ -2049,7 +2049,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
void CheckClass::checkConstError(const Token *tok, const std::string &classname, const std::string &funcname, bool suggestStatic)
{
checkConstError2(tok, 0, classname, funcname, suggestStatic);
checkConstError2(tok, nullptr, classname, funcname, suggestStatic);
}
void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname, bool suggestStatic)

View File

@ -197,8 +197,8 @@ private:
c.memsetError(nullptr, "memfunc", "classname", "class");
c.memsetErrorReference(nullptr, "memfunc", "class");
c.memsetErrorFloat(nullptr, "class");
c.mallocOnClassWarning(nullptr, "malloc", 0);
c.mallocOnClassError(nullptr, "malloc", 0, "std::string");
c.mallocOnClassWarning(nullptr, "malloc", nullptr);
c.mallocOnClassError(nullptr, "malloc", nullptr, "std::string");
c.operatorEqReturnError(nullptr, "class");
c.virtualDestructorError(nullptr, "Base", "Derived", false);
c.thisSubtractionError(nullptr);
@ -208,10 +208,10 @@ private:
c.operatorEqToSelfError(nullptr);
c.checkConstError(nullptr, "class", "function", false);
c.checkConstError(nullptr, "class", "function", true);
c.initializerListError(nullptr, 0, "class", "variable");
c.initializerListError(nullptr, nullptr, "class", "variable");
c.suggestInitializationList(nullptr, "variable");
c.selfInitializationError(nullptr, "var");
c.duplInheritedMembersError(nullptr, 0, "class", "class", "variable", false, false);
c.duplInheritedMembersError(nullptr, nullptr, "class", "class", "variable", false, false);
c.copyCtorAndEqOperatorError(nullptr, "class", false, false);
}

View File

@ -63,7 +63,7 @@ void CheckCondition::assignIf()
if (Token::Match(tok->tokAt(-2), "[;{}] %var% =")) {
const Variable *var = tok->previous()->variable();
if (var == 0)
if (var == nullptr)
continue;
char bitop = '\0';
@ -241,7 +241,7 @@ static void getnumchildren(const Token *tok, std::list<MathLib::bigint> &numchil
/* Return whether tok is in the body for a function returning a boolean. */
static bool inBooleanFunction(const Token *tok)
{
const Scope *scope = tok ? tok->scope() : 0;
const Scope *scope = tok ? tok->scope() : nullptr;
while (scope && scope->isLocal())
scope = scope->nestedIn;
if (scope && scope->type == Scope::eFunction) {

View File

@ -138,12 +138,12 @@ private:
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckCondition c(nullptr, settings, errorLogger);
c.assignIfError(nullptr, 0, emptyString, false);
c.assignIfError(nullptr, nullptr, emptyString, false);
c.badBitmaskCheckError(nullptr);
c.comparisonError(nullptr, "&", 6, "==", 1, false);
c.multiConditionError(nullptr,1);
c.mismatchingBitAndError(nullptr, 0xf0, 0, 1);
c.oppositeInnerConditionError(nullptr, 0);
c.mismatchingBitAndError(nullptr, 0xf0, nullptr, 1);
c.oppositeInnerConditionError(nullptr, nullptr);
c.incorrectLogicOperatorError(nullptr, "foo > 3 && foo < 4", true, false);
c.redundantConditionError(nullptr, "If x > 11 the condition x > 10 is always true.", false);
c.moduloAlwaysTrueFalseError(nullptr, "1");

View File

@ -144,7 +144,7 @@ private:
c.rethrowCopyError(nullptr, "varname");
c.catchExceptionByValueError(nullptr);
c.noexceptThrowError(nullptr);
c.unhandledExceptionSpecificationError(nullptr, 0, "funcname");
c.unhandledExceptionSpecificationError(nullptr, nullptr, "funcname");
}
/** Short description of class (for --doc) */

View File

@ -1413,7 +1413,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings *settings,
top = top->astParent();
const ValueType *valuetype = top->argumentType();
if (valuetype && valuetype->type >= ValueType::Type::BOOL) {
typeToken = tempToken = new Token(0);
typeToken = tempToken = new Token(nullptr);
if (valuetype->pointer && valuetype->constness & 1) {
tempToken->str("const");
tempToken->insertToken("a");
@ -1490,7 +1490,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings *settings,
if (function->retType->classScope->enumType)
typeToken = function->retType->classScope->enumType;
else {
tempToken = new Token(0);
tempToken = new Token(nullptr);
tempToken->fileIndex(tok1->fileIndex());
tempToken->linenr(tok1->linenr());
tempToken->str("int");
@ -1511,7 +1511,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings *settings,
if (function->retType->classScope->enumType)
typeToken = function->retType->classScope->enumType;
else {
tempToken = new Token(0);
tempToken = new Token(nullptr);
tempToken->fileIndex(tok1->fileIndex());
tempToken->linenr(tok1->linenr());
tempToken->str("int");
@ -1536,7 +1536,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings *settings,
// check for some common well known functions
else if (isCPP && ((Token::Match(tok1->previous(), "%var% . size|empty|c_str ( ) [,)]") && isStdContainer(tok1->previous())) ||
(Token::Match(tok1->previous(), "] . size|empty|c_str ( ) [,)]") && isStdContainer(tok1->previous()->link()->previous())))) {
tempToken = new Token(0);
tempToken = new Token(nullptr);
tempToken->fileIndex(tok1->fileIndex());
tempToken->linenr(tok1->linenr());
if (tok1->next()->str() == "size") {
@ -1576,8 +1576,8 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings *settings,
variableInfo = varTok->variable();
if (!variableInfo || !isStdVectorOrString()) {
variableInfo = 0;
typeToken = 0;
variableInfo = nullptr;
typeToken = nullptr;
}
return;
@ -1597,7 +1597,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings *settings,
if (variableInfo->type() && variableInfo->type()->classScope && variableInfo->type()->classScope->enumType)
typeToken = variableInfo->type()->classScope->enumType;
else {
tempToken = new Token(0);
tempToken = new Token(nullptr);
tempToken->fileIndex(tok1->fileIndex());
tempToken->linenr(tok1->linenr());
tempToken->str("int");
@ -1636,7 +1636,7 @@ bool CheckIO::ArgumentInfo::isStdVectorOrString()
_template = true;
return true;
} else if (variableInfo->isStlType(stl_string)) {
tempToken = new Token(0);
tempToken = new Token(nullptr);
tempToken->fileIndex(variableInfo->typeStartToken()->fileIndex());
tempToken->linenr(variableInfo->typeStartToken()->linenr());
if (variableInfo->typeStartToken()->strAt(2) == "string")
@ -1654,7 +1654,7 @@ bool CheckIO::ArgumentInfo::isStdVectorOrString()
_template = true;
return true;
} else if (Token::Match(nameTok, "std :: string|wstring")) {
tempToken = new Token(0);
tempToken = new Token(nullptr);
tempToken->fileIndex(variableInfo->typeStartToken()->fileIndex());
tempToken->linenr(variableInfo->typeStartToken()->linenr());
if (nameTok->strAt(2) == "string")

View File

@ -299,7 +299,7 @@ void CheckMemoryLeak::reportErr(const Token *tok, Severity::SeverityType severit
void CheckMemoryLeak::reportErr(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const
{
const ErrorLogger::ErrorMessage errmsg(callstack, tokenizer?&tokenizer->list:0, severity, id, msg, cwe, false);
const ErrorLogger::ErrorMessage errmsg(callstack, tokenizer ? &tokenizer->list : nullptr, severity, id, msg, cwe, false);
if (errorLogger)
errorLogger->reportErr(errmsg);
else
@ -527,7 +527,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
{
if (test_white_list(tok->str(), _settings, tokenizer->isCPP())) {
if (call_func_keywords.find(tok->str())!=call_func_keywords.end())
return 0;
return nullptr;
// is the varid a parameter?
for (const Token *tok2 = tok->tokAt(2); tok2 && tok2 != tok->linkAt(1); tok2 = tok2->next()) {
@ -548,14 +548,14 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
}
}
return 0;
return nullptr;
}
if (_settings->library.isnoreturn(tok) && tok->strAt(-1) != "=")
return "exit";
if (varid > 0 && (getReallocationType(tok, varid) != No || getDeallocationType(tok, varid) != No))
return 0;
return nullptr;
if (callstack.size() > 2)
return "dealloc_";
@ -571,7 +571,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
if (varid == 0) {
const Function* func = tok->function();
if (!func || !func->hasBody())
return 0;
return nullptr;
Token *ftok = getcode(func->functionScope->classStart->next(), callstack, 0, alloctype, dealloctype, false, 1);
simplifycode(ftok);
@ -669,7 +669,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
if (Token::Match(tok, "%varid% . %name% [,)]", varid))
return "use";
}
return (eq || _settings->experimental) ? 0 : "callfunc";
return (eq || _settings->experimental) ? nullptr : "callfunc";
}
@ -689,7 +689,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
std::set<unsigned int> extravar;
// The first token should be ";"
Token* rethead = new Token(0);
Token* rethead = new Token(nullptr);
rethead->str(";");
rethead->linenr(tok->linenr());
rethead->fileIndex(tok->fileIndex());
@ -802,7 +802,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
// todo: check how the return value is used.
if (!Token::Match(tok->previous(), "[;{}]")) {
TokenList::deleteTokens(rethead);
return 0;
return nullptr;
}
alloc = Malloc;
tok = tok->next()->link();
@ -2060,7 +2060,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *startTok, const std::str
}
// If the variable is not allocated at all => no memory leak
if (Token::findsimplematch(tok, "alloc") == 0) {
if (Token::findsimplematch(tok, "alloc") == nullptr) {
TokenList::deleteTokens(tok);
return;
}
@ -2072,7 +2072,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *startTok, const std::str
}
// If the variable is not allocated at all => no memory leak
if (Token::findsimplematch(tok, "alloc") == 0) {
if (Token::findsimplematch(tok, "alloc") == nullptr) {
TokenList::deleteTokens(tok);
return;
}
@ -2113,7 +2113,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *startTok, const std::str
// Unhandled case..
if (!noerr)
reportError(first, Severity::debug, "debug",
"inconclusive leak of " + varname + ": " + tok->stringifyList(false, false, false, false, false, 0, 0));
"inconclusive leak of " + varname + ": " + tok->stringifyList(false, false, false, false, false, nullptr, nullptr));
}
TokenList::deleteTokens(tok);
@ -2196,7 +2196,7 @@ static bool isInMemberFunc(const Scope* scope)
while (scope->nestedIn && !scope->functionOf)
scope = scope->nestedIn;
return (scope->functionOf != 0);
return (scope->functionOf != nullptr);
}
void CheckMemoryLeakInFunction::check()

View File

@ -181,7 +181,7 @@ public:
class CPPCHECKLIB CheckMemoryLeakInFunction : private Check, public CheckMemoryLeak {
public:
/** @brief This constructor is used when registering this class */
CheckMemoryLeakInFunction() : Check(myName()), CheckMemoryLeak(0, 0, 0), symbolDatabase(nullptr) {
CheckMemoryLeakInFunction() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr), symbolDatabase(nullptr) {
}
/** @brief This constructor is used when running checks */
@ -191,7 +191,7 @@ public:
if (tokenizr)
symbolDatabase = tokenizr->getSymbolDatabase();
else
symbolDatabase = 0;
symbolDatabase = nullptr;
}
/** @brief run all simplified checks */
@ -329,7 +329,7 @@ private:
class CPPCHECKLIB CheckMemoryLeakInClass : private Check, private CheckMemoryLeak {
public:
CheckMemoryLeakInClass() : Check(myName()), CheckMemoryLeak(0, 0, 0) {
CheckMemoryLeakInClass() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {
}
CheckMemoryLeakInClass(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
@ -356,9 +356,9 @@ private:
void unsafeClassError(const Token *tok, const std::string &classname, const std::string &varname);
void getErrorMessages(ErrorLogger *e, const Settings *settings) const {
CheckMemoryLeakInClass c(0, settings, e);
c.publicAllocationError(0, "varname");
c.unsafeClassError(0, "class", "class::varname");
CheckMemoryLeakInClass c(nullptr, settings, e);
c.publicAllocationError(nullptr, "varname");
c.unsafeClassError(nullptr, "class", "class::varname");
}
static std::string myName() {
@ -376,7 +376,7 @@ private:
class CPPCHECKLIB CheckMemoryLeakStructMember : private Check, private CheckMemoryLeak {
public:
CheckMemoryLeakStructMember() : Check(myName()), CheckMemoryLeak(0, 0, 0) {
CheckMemoryLeakStructMember() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {
}
CheckMemoryLeakStructMember(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
@ -415,7 +415,7 @@ private:
class CPPCHECKLIB CheckMemoryLeakNoVar : private Check, private CheckMemoryLeak {
public:
CheckMemoryLeakNoVar() : Check(myName()), CheckMemoryLeak(0, 0, 0) {
CheckMemoryLeakNoVar() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {
}
CheckMemoryLeakNoVar(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)

View File

@ -387,7 +387,7 @@ void CheckNullPointer::nullConstantDereference()
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
if (scope->function == 0 || !scope->function->hasBody()) // We only look for functions with a body
if (scope->function == nullptr || !scope->function->hasBody()) // We only look for functions with a body
continue;
const Token *tok = scope->classStart;

View File

@ -1209,7 +1209,7 @@ bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& us
if (Token::simpleMatch(tok, "for ("))
forHeadEnd = tok->linkAt(1);
if (tok == forHeadEnd)
forHeadEnd = 0;
forHeadEnd = nullptr;
if (loopVariable && noContinue && tok->scope() == scope && !forHeadEnd && scope->type != Scope::eSwitch && Token::Match(tok, "%varid% =", var->declarationId())) { // Assigned in outer scope.
loopVariable = false;

View File

@ -275,8 +275,8 @@ private:
//performance
c.redundantCopyError(nullptr, "varname");
c.redundantCopyError(nullptr, 0, "var");
c.redundantAssignmentError(nullptr, 0, "var", false);
c.redundantCopyError(nullptr, nullptr, "var");
c.redundantAssignmentError(nullptr, nullptr, "var", false);
// style/warning
c.checkComparisonFunctionIsAlwaysTrueOrFalseError(nullptr, "isless","varName",false);
@ -288,15 +288,15 @@ private:
c.unknownSignCharArrayIndexError(nullptr);
c.charBitOpError(nullptr);
c.variableScopeError(nullptr, "varname");
c.redundantAssignmentInSwitchError(nullptr, 0, "var");
c.redundantCopyInSwitchError(nullptr, 0, "var");
c.redundantAssignmentInSwitchError(nullptr, nullptr, "var");
c.redundantCopyInSwitchError(nullptr, nullptr, "var");
c.suspiciousCaseInSwitchError(nullptr, "||");
c.suspiciousEqualityComparisonError(nullptr);
c.selfAssignmentError(nullptr, "varname");
c.clarifyCalculationError(nullptr, "+");
c.clarifyStatementError(nullptr);
c.duplicateBranchError(nullptr, 0);
c.duplicateExpressionError(nullptr, 0, "&&");
c.duplicateBranchError(nullptr, nullptr);
c.duplicateExpressionError(nullptr, nullptr, "&&");
c.duplicateExpressionTernaryError(nullptr);
c.duplicateBreakError(nullptr, false);
c.unreachableCodeError(nullptr, false);

View File

@ -188,19 +188,19 @@ void CheckSizeof::checkSizeofForPointerSize()
// Only keep variables which are pointers
const Variable *var = variable->variable();
if (!var || !var->isPointer() || var->isArray()) {
variable = 0;
variable = nullptr;
}
if (variable2) {
var = variable2->variable();
if (!var || !var->isPointer() || var->isArray()) {
variable2 = 0;
variable2 = nullptr;
}
}
// If there are no pointer variable at this point, there is
// no need to continue
if (variable == 0 && variable2 == 0) {
if (variable == nullptr && variable2 == nullptr) {
continue;
}

View File

@ -212,7 +212,7 @@ private:
c.string_c_strReturn(nullptr);
c.string_c_strParam(nullptr, 0);
c.sizeError(nullptr);
c.missingComparisonError(nullptr, 0);
c.missingComparisonError(nullptr, nullptr);
c.redundantIfRemoveError(nullptr);
c.autoPointerError(nullptr);
c.autoPointerContainerError(nullptr);

View File

@ -101,7 +101,7 @@ private:
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckString c(nullptr, settings, errorLogger);
c.stringLiteralWriteError(nullptr,0);
c.stringLiteralWriteError(nullptr, nullptr);
c.sprintfOverlappingDataError(nullptr, "varname");
c.strPlusCharError(nullptr);
c.incorrectStringCompareError(nullptr, "substr", "\"Hello World\"");

View File

@ -127,7 +127,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
}
if (!doMarkup // only check source files
&& settings->library.isexporter(tok->str()) && tok->next() != 0) {
&& settings->library.isexporter(tok->str()) && tok->next() != nullptr) {
const Token * propToken = tok->next();
while (propToken && propToken->str() != ")") {
if (settings->library.isexportedprefix(tok->str(), propToken->str())) {

View File

@ -62,7 +62,7 @@ public:
bool modified = false,
bool allocateMemory = false) :
_var(var),
_lastAccess(var?var->nameToken():0),
_lastAccess(var ? var->nameToken() : nullptr),
_type(type),
_read(read),
_write(write),
@ -387,7 +387,7 @@ Variables::VariableUsage *Variables::find(unsigned int varid)
if (i != _varUsage.end())
return &i->second;
}
return 0;
return nullptr;
}
void Variables::enterScope()

View File

@ -134,7 +134,7 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
plistFile.close();
}
CheckUnusedFunctions checkUnusedFunctions(0,0,0);
CheckUnusedFunctions checkUnusedFunctions(nullptr, nullptr, nullptr);
bool internalErrorFound(false);
try {

View File

@ -235,7 +235,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
}
if (elem != 5)
throw InternalError(0, "Internal Error: Deserialization of error message failed");
throw InternalError(nullptr, "Internal Error: Deserialization of error message failed");
_id = results[0];
_severity = Severity::fromString(results[1]);
@ -262,10 +262,10 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
const std::string::size_type colonPos = temp.find(':');
if (colonPos == std::string::npos)
throw InternalError(0, "Internal Error: No colon found in <filename:line> pattern");
throw InternalError(nullptr, "Internal Error: No colon found in <filename:line> pattern");
const std::string::size_type tabPos = temp.find('\t');
if (tabPos == std::string::npos)
throw InternalError(0, "Internal Error: No tab found in <filename:line> pattern");
throw InternalError(nullptr, "Internal Error: No tab found in <filename:line> pattern");
const std::string tempinfo = temp.substr(tabPos + 1);
temp.erase(tabPos);
@ -337,7 +337,7 @@ std::string ErrorLogger::ErrorMessage::fixInvalidChars(const std::string& raw)
std::string ErrorLogger::ErrorMessage::toXML() const
{
tinyxml2::XMLPrinter printer(0, false, 2);
tinyxml2::XMLPrinter printer(nullptr, false, 2);
printer.OpenElement("error", false);
printer.PushAttribute("id", _id.c_str());
printer.PushAttribute("severity", Severity::toString(_severity).c_str());

View File

@ -711,7 +711,7 @@ bool Library::isargvalid(const Token *ftok, int argnr, const MathLib::bigint arg
const ArgumentChecks *ac = getarg(ftok, argnr);
if (!ac || ac->valid.empty())
return true;
TokenList tokenList(0);
TokenList tokenList(nullptr);
std::istringstream istr(ac->valid + ',');
tokenList.createTokens(istr);
for (Token *tok = tokenList.front(); tok; tok = tok->next()) {
@ -827,14 +827,14 @@ bool Library::isuninitargbad(const Token *ftok, int argnr) const
const Library::AllocFunc* Library::alloc(const Token *tok) const
{
const std::string funcname = getFunctionName(tok);
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? 0 : getAllocDealloc(_alloc, funcname);
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(_alloc, funcname);
}
/** get deallocation info for function */
const Library::AllocFunc* Library::dealloc(const Token *tok) const
{
const std::string funcname = getFunctionName(tok);
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? 0 : getAllocDealloc(_dealloc, funcname);
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(_dealloc, funcname);
}
/** get allocation id for function */

View File

@ -49,7 +49,7 @@ MathLib::value::value(const std::string &s) :
}
if (!MathLib::isInt(s))
throw InternalError(0, "Invalid value: " + s);
throw InternalError(nullptr, "Invalid value: " + s);
type = MathLib::value::INT;
intValue = MathLib::toLongNumber(s);
@ -147,9 +147,9 @@ MathLib::value MathLib::value::calc(char op, const MathLib::value &v1, const Mat
case '&':
case '|':
case '^':
throw InternalError(0, "Invalid calculation");
throw InternalError(nullptr, "Invalid calculation");
default:
throw InternalError(0, "Unhandled calculation");
throw InternalError(nullptr, "Unhandled calculation");
}
} else if (temp.isUnsigned) {
switch (op) {
@ -164,14 +164,14 @@ MathLib::value MathLib::value::calc(char op, const MathLib::value &v1, const Mat
break;
case '/':
if (v2.intValue == 0)
throw InternalError(0, "Internal Error: Division by zero");
throw InternalError(nullptr, "Internal Error: Division by zero");
if (v1.intValue == std::numeric_limits<bigint>::min() && std::abs(v2.intValue)<=1)
throw InternalError(0, "Internal Error: Division overflow");
throw InternalError(nullptr, "Internal Error: Division overflow");
temp.intValue /= (unsigned long long)v2.intValue;
break;
case '%':
if (v2.intValue == 0)
throw InternalError(0, "Internal Error: Division by zero");
throw InternalError(nullptr, "Internal Error: Division by zero");
temp.intValue %= (unsigned long long)v2.intValue;
break;
case '&':
@ -184,7 +184,7 @@ MathLib::value MathLib::value::calc(char op, const MathLib::value &v1, const Mat
temp.intValue ^= (unsigned long long)v2.intValue;
break;
default:
throw InternalError(0, "Unhandled calculation");
throw InternalError(nullptr, "Unhandled calculation");
}
} else {
switch (op) {
@ -199,14 +199,14 @@ MathLib::value MathLib::value::calc(char op, const MathLib::value &v1, const Mat
break;
case '/':
if (v2.intValue == 0)
throw InternalError(0, "Internal Error: Division by zero");
throw InternalError(nullptr, "Internal Error: Division by zero");
if (v1.intValue == std::numeric_limits<bigint>::min() && std::abs(v2.intValue)<=1)
throw InternalError(0, "Internal Error: Division overflow");
throw InternalError(nullptr, "Internal Error: Division overflow");
temp.intValue /= v2.intValue;
break;
case '%':
if (v2.intValue == 0)
throw InternalError(0, "Internal Error: Division by zero");
throw InternalError(nullptr, "Internal Error: Division by zero");
temp.intValue %= v2.intValue;
break;
case '&':
@ -219,7 +219,7 @@ MathLib::value MathLib::value::calc(char op, const MathLib::value &v1, const Mat
temp.intValue ^= v2.intValue;
break;
default:
throw InternalError(0, "Unhandled calculation");
throw InternalError(nullptr, "Unhandled calculation");
}
}
return temp;
@ -267,7 +267,7 @@ MathLib::value MathLib::value::add(int v) const
MathLib::value MathLib::value::shiftLeft(const MathLib::value &v) const
{
if (!isInt() || !v.isInt())
throw InternalError(0, "Shift operand is not integer");
throw InternalError(nullptr, "Shift operand is not integer");
MathLib::value ret(*this);
ret.intValue <<= v.intValue;
return ret;
@ -276,7 +276,7 @@ MathLib::value MathLib::value::shiftLeft(const MathLib::value &v) const
MathLib::value MathLib::value::shiftRight(const MathLib::value &v) const
{
if (!isInt() || !v.isInt())
throw InternalError(0, "Shift operand is not integer");
throw InternalError(nullptr, "Shift operand is not integer");
MathLib::value ret(*this);
ret.intValue >>= v.intValue;
return ret;
@ -358,7 +358,7 @@ MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str)
// '\xF6'
if (str.size() == 4 && str.compare(0,2,"\\x")==0 && std::isxdigit(str[2]) && std::isxdigit(str[3])) {
return std::strtoul(str.substr(2).c_str(), NULL, 16);
return std::strtoul(str.substr(2).c_str(), nullptr, 16);
}
// '\123'
@ -386,14 +386,14 @@ std::string MathLib::normalizeCharacterLiteral(const std::string& iLiteral)
}
++idx;
if (idx == iLiteralLen) {
throw InternalError(0, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'.");
throw InternalError(nullptr, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'.");
}
switch (iLiteral[idx]) {
case 'x':
// Hexa-decimal number: skip \x and interpret the next two characters
{
if (++idx == iLiteralLen)
throw InternalError(0, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'.");
throw InternalError(nullptr, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'.");
std::string tempBuf;
tempBuf.push_back(iLiteral[idx]);
if (++idx != iLiteralLen)
@ -405,7 +405,7 @@ std::string MathLib::normalizeCharacterLiteral(const std::string& iLiteral)
case 'U':
// Unicode string; just skip the \u or \U
if (idx + 1 == iLiteralLen)
throw InternalError(0, "Internal Error. MathLib::characterLiteralToLongNumber: Unhandled char constant '" + iLiteral + "'.");
throw InternalError(nullptr, "Internal Error. MathLib::characterLiteralToLongNumber: Unhandled char constant '" + iLiteral + "'.");
continue;
}
// Single digit octal number
@ -452,13 +452,13 @@ std::string MathLib::normalizeCharacterLiteral(const std::string& iLiteral)
normalizedLiteral.push_back(iLiteral[idx]);
break;
default:
throw InternalError(0, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'.");
throw InternalError(nullptr, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'.");
}
continue;
}
// 2-3 digit octal number
if (!MathLib::isOctalDigit(iLiteral[idx]))
throw InternalError(0, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'.");
throw InternalError(nullptr, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'.");
std::string tempBuf;
tempBuf.push_back(iLiteral[idx]);
++idx;
@ -554,7 +554,7 @@ double MathLib::toDoubleNumber(const std::string &str)
#ifdef __clang__
if (isFloat(str)) // Workaround libc++ bug at http://llvm.org/bugs/show_bug.cgi?id=17782
// TODO : handle locale
return std::strtod(str.c_str(), 0);
return std::strtod(str.c_str(), nullptr);
#endif
// otherwise, convert to double
std::istringstream istr(str);
@ -1136,7 +1136,7 @@ std::string MathLib::incdec(const std::string & var, const std::string & op)
return MathLib::subtract(var, "1");
#endif
throw InternalError(0, std::string("Unexpected operation '") + op + "' in MathLib::incdec(). Please report this to Cppcheck developers.");
throw InternalError(nullptr, std::string("Unexpected operation '") + op + "' in MathLib::incdec(). Please report this to Cppcheck developers.");
}
std::string MathLib::divide(const std::string &first, const std::string &second)
@ -1148,9 +1148,9 @@ std::string MathLib::divide(const std::string &first, const std::string &second)
const bigint a = toLongNumber(first);
const bigint b = toLongNumber(second);
if (b == 0)
throw InternalError(0, "Internal Error: Division by zero");
throw InternalError(nullptr, "Internal Error: Division by zero");
if (a == std::numeric_limits<bigint>::min() && std::abs(b)<=1)
throw InternalError(0, "Internal Error: Division overflow");
throw InternalError(nullptr, "Internal Error: Division overflow");
return toString(toLongNumber(first) / b) + intsuffix(first, second);
} else if (isNullValue(second)) {
if (isNullValue(first))
@ -1181,7 +1181,7 @@ std::string MathLib::mod(const std::string &first, const std::string &second)
if (MathLib::isInt(first) && MathLib::isInt(second)) {
const bigint b = toLongNumber(second);
if (b == 0)
throw InternalError(0, "Internal Error: Division by zero");
throw InternalError(nullptr, "Internal Error: Division by zero");
return toString(toLongNumber(first) % b) + intsuffix(first, second);
}
return toString(std::fmod(toDoubleNumber(first),toDoubleNumber(second)));
@ -1216,7 +1216,7 @@ std::string MathLib::calculate(const std::string &first, const std::string &seco
return MathLib::toString(MathLib::toLongNumber(first) ^ MathLib::toLongNumber(second)) + intsuffix(first,second);
default:
throw InternalError(0, std::string("Unexpected action '") + action + "' in MathLib::calculate(). Please report this to Cppcheck developers.");
throw InternalError(nullptr, std::string("Unexpected action '") + action + "' in MathLib::calculate(). Please report this to Cppcheck developers.");
}
}

View File

@ -142,7 +142,7 @@ const std::string Path::getCurrentPath()
char currentPath[4096];
#ifndef _WIN32
if (getcwd(currentPath, 4096) != 0)
if (getcwd(currentPath, 4096) != nullptr)
#else
if (_getcwd(currentPath, 4096) != 0)
#endif

View File

@ -909,7 +909,7 @@ void Preprocessor::simplifyPragmaAsmPrivate(simplecpp::TokenList *tokenList)
continue;
const simplecpp::Token *endasm = tok3;
while ((endasm = endasm->next) != 0) {
while ((endasm = endasm->next) != nullptr) {
if (endasm->op != '#' || sameline(endasm,endasm->previousSkipComments()))
continue;
const simplecpp::Token * const endasm2 = endasm->nextSkipComments();

View File

@ -243,7 +243,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
tok->strAt(-1) != "friend") {
if (!findType(tok->next(), scope)) {
// fill typeList..
typeList.push_back(Type(tok, 0, scope));
typeList.push_back(Type(tok, nullptr, scope));
scope->definedTypes.push_back(&typeList.back());
}
tok = tok->tokAt(2);
@ -341,7 +341,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
// forward declared enum
else if (Token::Match(tok, "enum class| %name% ;") || Token::Match(tok, "enum class| %name% : %name% ;")) {
typeList.push_back(Type(tok, 0, scope));
typeList.push_back(Type(tok, nullptr, scope));
scope->definedTypes.push_back(&typeList.back());
tok = tok->tokAt(2);
}
@ -645,7 +645,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
friendInfo.name = friendInfo.nameEnd->str();
// fill this in after parsing is complete
friendInfo.type = 0;
friendInfo.type = nullptr;
if (!scope->definedType)
_tokenizer->syntaxError(tok);
@ -1477,12 +1477,12 @@ SymbolDatabase::~SymbolDatabase()
{
// Clear scope, type, function and variable pointers
for (const Token* tok = _tokenizer->list.front(); tok; tok = tok->next()) {
const_cast<Token *>(tok)->scope(0);
const_cast<Token *>(tok)->type(0);
const_cast<Token *>(tok)->function(0);
const_cast<Token *>(tok)->variable(0);
const_cast<Token *>(tok)->enumerator(0);
const_cast<Token *>(tok)->setValueType(0);
const_cast<Token *>(tok)->scope(nullptr);
const_cast<Token *>(tok)->type(nullptr);
const_cast<Token *>(tok)->function(nullptr);
const_cast<Token *>(tok)->variable(nullptr);
const_cast<Token *>(tok)->enumerator(nullptr);
const_cast<Token *>(tok)->setValueType(nullptr);
}
}
@ -2379,7 +2379,7 @@ const Function* Type::getFunction(const std::string& funcName) const
return func;
}
}
return 0;
return nullptr;
}
bool Type::hasCircularDependencies(std::set<BaseInfo>* ancestors) const
@ -3173,9 +3173,9 @@ const Variable* Function::getArgumentVar(std::size_t num) const
if (i->index() == num)
return (&*i);
else if (i->index() > num)
return 0;
return nullptr;
}
return 0;
return nullptr;
}
@ -4275,7 +4275,7 @@ const Function* SymbolDatabase::findFunction(const Token *tok) const
currScope = currScope->nestedIn;
}
}
return 0;
return nullptr;
}
//---------------------------------------------------------------------------
@ -4286,7 +4286,7 @@ const Scope *SymbolDatabase::findScopeByName(const std::string& name) const
if (it->className == name)
return &*it;
}
return 0;
return nullptr;
}
//---------------------------------------------------------------------------
@ -4299,7 +4299,7 @@ Scope *Scope::findInNestedList(const std::string & name)
if ((*it)->className == name)
return (*it);
}
return 0;
return nullptr;
}
//---------------------------------------------------------------------------
@ -4312,7 +4312,7 @@ const Scope *Scope::findRecordInNestedList(const std::string & name) const
if ((*it)->className == name && (*it)->type != eFunction)
return (*it);
}
return 0;
return nullptr;
}
//---------------------------------------------------------------------------
@ -4325,7 +4325,7 @@ const Type* Scope::findType(const std::string & name) const
if ((*it)->name() == name)
return (*it);
}
return 0;
return nullptr;
}
//---------------------------------------------------------------------------
@ -4344,7 +4344,7 @@ Scope *Scope::findInNestedListRecursive(const std::string & name)
if (child)
return child;
}
return 0;
return nullptr;
}
//---------------------------------------------------------------------------
@ -4356,7 +4356,7 @@ const Function *Scope::getDestructor() const
if (it->type == Function::eDestructor)
return &(*it);
}
return 0;
return nullptr;
}
//---------------------------------------------------------------------------
@ -4390,7 +4390,7 @@ const Scope *SymbolDatabase::findScope(const Token *tok, const Scope *startScope
}
// not a valid path
return 0;
return nullptr;
}
//---------------------------------------------------------------------------
@ -4470,7 +4470,7 @@ const Type* SymbolDatabase::findType(const Token *startTok, const Scope *startSc
}
// not a valid path
return 0;
return nullptr;
}
//---------------------------------------------------------------------------
@ -4523,7 +4523,7 @@ const Type* SymbolDatabase::findTypeInNested(const Token *startTok, const Scope
}
// not a valid path
return 0;
return nullptr;
}
//---------------------------------------------------------------------------
@ -4537,7 +4537,7 @@ const Scope * SymbolDatabase::findNamespace(const Token * tok, const Scope * sco
else if (scope->nestedIn)
return findNamespace(tok, scope->nestedIn);
return 0;
return nullptr;
}
//---------------------------------------------------------------------------

View File

@ -100,7 +100,7 @@ public:
std::vector<BaseInfo> derivedFrom;
std::list<FriendInfo> friendList;
Type(const Token* classDef_ = 0, const Scope* classScope_ = 0, const Scope* enclosingScope_ = 0) :
Type(const Token* classDef_ = nullptr, const Scope* classScope_ = nullptr, const Scope* enclosingScope_ = nullptr) :
classDef(classDef_),
classScope(classScope_),
enclosingScope(enclosingScope_),
@ -479,7 +479,7 @@ public:
* @return pointer to type scope if known, NULL if not known
*/
const Scope *typeScope() const {
return _type ? _type->classScope : 0;
return _type ? _type->classScope : nullptr;
}
/**

View File

@ -1381,7 +1381,7 @@ void TemplateSimplifier::replaceTemplateUsage(Token * const instantiationToken,
// match parameters
Token * tok2 = nameTok->tokAt(2);
unsigned int typeCountInInstantiation = 1U; // There is always at least one type
const Token *typetok = (!typesUsedInTemplateInstantiation.empty()) ? typesUsedInTemplateInstantiation[0] : 0;
const Token *typetok = (!typesUsedInTemplateInstantiation.empty()) ? typesUsedInTemplateInstantiation[0] : nullptr;
unsigned int indentlevel2 = 0; // indentlevel for tokgt
while (tok2 && (indentlevel2 > 0 || tok2->str() != ">")) {
if (tok2->str() == "<" && templateParameters(tok2) > 0)

View File

@ -35,11 +35,11 @@
Token::Token(Token **tokens) :
tokensBack(tokens),
_next(0),
_previous(0),
_link(0),
_scope(0),
_function(0), // Initialize whole union
_next(nullptr),
_previous(nullptr),
_link(nullptr),
_scope(nullptr),
_function(nullptr), // Initialize whole union
_varId(0),
_fileIndex(0),
_linenr(0),
@ -591,7 +591,7 @@ const char *Token::chrInFirstWord(const char *str, char c)
{
for (;;) {
if (*str == ' ' || *str == 0)
return 0;
return nullptr;
if (*str == c)
return str;
@ -868,7 +868,7 @@ const Token *Token::findsimplematch(const Token * const startTok, const char pat
if (Token::simpleMatch(tok, pattern))
return tok;
}
return 0;
return nullptr;
}
const Token *Token::findsimplematch(const Token * const startTok, const char pattern[], const Token * const end)
@ -962,14 +962,14 @@ void Token::printOut(const char *title) const
{
if (title && title[0])
std::cout << "\n### " << title << " ###\n";
std::cout << stringifyList(true, true, true, true, true, 0, 0) << std::endl;
std::cout << stringifyList(true, true, true, true, true, nullptr, nullptr) << std::endl;
}
void Token::printOut(const char *title, const std::vector<std::string> &fileNames) const
{
if (title && title[0])
std::cout << "\n### " << title << " ###\n";
std::cout << stringifyList(true, true, true, true, true, &fileNames, 0) << std::endl;
std::cout << stringifyList(true, true, true, true, true, &fileNames, nullptr) << std::endl;
}
void Token::stringify(std::ostream& os, bool varid, bool attributes, bool macro) const
@ -1067,12 +1067,12 @@ std::string Token::stringifyList(bool varid, bool attributes, bool linenumbers,
std::string Token::stringifyList(const Token* end, bool attributes) const
{
return stringifyList(false, attributes, false, false, false, 0, end);
return stringifyList(false, attributes, false, false, false, nullptr, end);
}
std::string Token::stringifyList(bool varid) const
{
return stringifyList(varid, false, true, true, true, 0, 0);
return stringifyList(varid, false, true, true, true, nullptr, nullptr);
}
void Token::astOperand1(Token *tok)

View File

@ -556,7 +556,7 @@ public:
* @param end Stringification ends before this token is reached. 0 to stringify until end of list.
* @return Stringified token list as a string
*/
std::string stringifyList(bool varid, bool attributes, bool linenumbers, bool linebreaks, bool files, const std::vector<std::string>* fileNames = 0, const Token* end = 0) const;
std::string stringifyList(bool varid, bool attributes, bool linenumbers, bool linebreaks, bool files, const std::vector<std::string>* fileNames = nullptr, const Token* end = nullptr) const;
std::string stringifyList(const Token* end, bool attributes = true) const;
std::string stringifyList(bool varid = false) const;
@ -625,7 +625,7 @@ public:
* @return a pointer to the Function associated with this token.
*/
const Function *function() const {
return _tokType == eFunction ? _function : 0;
return _tokType == eFunction ? _function : nullptr;
}
/**
@ -644,7 +644,7 @@ public:
* @return a pointer to the variable associated with this token.
*/
const Variable *variable() const {
return _tokType == eVariable ? _variable : 0;
return _tokType == eVariable ? _variable : nullptr;
}
/**
@ -657,14 +657,14 @@ public:
* @return a pointer to the type associated with this token.
*/
const ::Type *type() const {
return _tokType == eType ? _type : 0;
return _tokType == eType ? _type : nullptr;
}
/**
* @return a pointer to the Enumerator associated with this token.
*/
const Enumerator *enumerator() const {
return _tokType == eEnumerator ? _enumerator : 0;
return _tokType == eEnumerator ? _enumerator : nullptr;
}
/**

View File

@ -134,10 +134,10 @@ static bool isClassStructUnionEnumStart(const Token * tok)
//---------------------------------------------------------------------------
Tokenizer::Tokenizer() :
list(0),
_settings(0),
_errorLogger(0),
_symbolDatabase(0),
list(nullptr),
_settings(nullptr),
_errorLogger(nullptr),
_symbolDatabase(nullptr),
_varId(0),
_codeWithTemplates(false), //is there any templates?
m_timerResults(nullptr)
@ -151,7 +151,7 @@ Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) :
list(settings),
_settings(settings),
_errorLogger(errorLogger),
_symbolDatabase(0),
_symbolDatabase(nullptr),
_varId(0),
_codeWithTemplates(false), //is there any templates?
m_timerResults(nullptr)
@ -2146,7 +2146,7 @@ static Token *skipTernaryOp(Token *tok)
break;
}
if (colonlevel) // Ticket #5214: Make sure the ':' matches the proper '?'
return 0;
return nullptr;
return tok;
}
@ -3019,7 +3019,7 @@ void Tokenizer::createLinks()
std::stack<Token*> links3;
for (Token *token = list.front(); token; token = token->next()) {
if (token->link()) {
token->link(0);
token->link(nullptr);
}
linkBrackets(this, type, links1, token, '{', '}');
@ -3069,7 +3069,7 @@ void Tokenizer::createLinks2()
type.pop();
templateToken = nullptr;
} else
token->link(0);
token->link(nullptr);
} else if (!templateToken && !isStruct && Token::Match(token, "%oror%|&&|;")) {
if (Token::Match(token, "&& [,>]"))
continue;
@ -3180,7 +3180,7 @@ bool Tokenizer::simplifySizeof()
else if (Token::Match(tok->previous(), "%type% %name% [ %num% ] [,)]") ||
Token::Match(tok->tokAt(-2), "%type% * %name% [ %num% ] [,)]")) {
Token tempTok(0);
Token tempTok(nullptr);
tempTok.str("*");
sizeOfVar[varId] = sizeOfType(&tempTok);
declTokOfVar[varId] = tok;
@ -3841,7 +3841,7 @@ void Tokenizer::printDebugOutput(unsigned int simplification) const
(simplification != 2U && _settings->debugnormal);
if (debug && list.front()) {
list.front()->printOut(0, list.getFiles());
list.front()->printOut(nullptr, list.getFiles());
if (_settings->xml)
std::cout << "<debug>" << std::endl;
@ -4233,7 +4233,7 @@ void Tokenizer::simplifyFlowControl()
break;
--indentlevel;
if (stilldead) {
eraseDeadCode(tok, 0);
eraseDeadCode(tok, nullptr);
if (indentlevel == 1 || tok->next()->str() != "}" || !Token::Match(tok->next()->link()->previous(), ";|{|}|do {"))
stilldead = false;
continue;
@ -4245,7 +4245,7 @@ void Tokenizer::simplifyFlowControl()
if (Token::Match(tok,"continue|break ;")) {
tok = tok->next();
eraseDeadCode(tok, 0);
eraseDeadCode(tok, nullptr);
} else if (Token::Match(tok,"return|goto") ||
(Token::Match(tok->previous(), "[;{}] %name% (") &&
@ -4260,7 +4260,7 @@ void Tokenizer::simplifyFlowControl()
tok2 = tok2->link();
} else if (tok2->str() == ";") {
tok = tok2;
eraseDeadCode(tok, 0);
eraseDeadCode(tok, nullptr);
break;
} else if (Token::Match(tok2, "[{}]"))
break;
@ -4608,7 +4608,7 @@ void Tokenizer::simplifyCompoundAssignment()
tok = tok->link();
// goto next token..
tok = tok ? tok->next() : 0;
tok = tok ? tok->next() : nullptr;
}
}
}
@ -4857,7 +4857,7 @@ bool Tokenizer::simplifyConstTernaryOp()
if (tok->str() == "<" && TemplateSimplifier::templateParameters(tok))
templateParameterEnd = tok->findClosingBracket();
if (tok == templateParameterEnd)
templateParameterEnd = 0; // End of the current template parameter list
templateParameterEnd = nullptr; // End of the current template parameter list
if (tok->str() != "?")
continue;
@ -7543,7 +7543,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
tok = tok->link()->tokAt(-2); //remove also 'switch ( ... )'
Token::eraseTokens(tok, end2->next());
checklabel = false;
tokcheck = 0;
tokcheck = nullptr;
indentcheck = 0;
} else {
tok = tok->next();

View File

@ -38,8 +38,8 @@ static const unsigned int AST_MAX_DEPTH = 50U;
TokenList::TokenList(const Settings* settings) :
_front(0),
_back(0),
_front(nullptr),
_back(nullptr),
_settings(settings),
_isC(false),
_isCPP(false)
@ -67,8 +67,8 @@ const std::string& TokenList::getSourceFilePath() const
void TokenList::deallocateTokens()
{
deleteTokens(_front);
_front = 0;
_back = 0;
_front = nullptr;
_back = nullptr;
_files.clear();
}
@ -892,7 +892,7 @@ static void compileAssignTernary(Token *&tok, AST_state& state)
// "The expression in the middle of the conditional operator (between ? and :) is parsed as if parenthesized: its precedence relative to ?: is ignored."
// Hence, we rely on Tokenizer::prepareTernaryOpForAST() to add such parentheses where necessary.
if (tok->strAt(1) == ":") {
state.op.push(0);
state.op.push(nullptr);
}
const unsigned int assign = state.assign;
state.assign = 0U;

View File

@ -2379,7 +2379,7 @@ static bool valueFlowForLoop1(const Token *tok, unsigned int * const varid, Math
if (num2tok && num2tok->str() == "(" && !num2tok->astOperand2())
num2tok = num2tok->astOperand1();
if (!Token::Match(num2tok, "%num% ;|%oror%")) // TODO: || enlarges the scope of the condition, so it should not cause FP, but it should no lnger be part of this pattern as soon as valueFlowForLoop2 can handle an unknown RHS of || better
num2tok = 0;
num2tok = nullptr;
}
if (!num2tok)
return false;

View File

@ -39,7 +39,7 @@ namespace ValueFlow {
typedef std::pair<const Token *, std::string> ErrorPathItem;
typedef std::list<ErrorPathItem> ErrorPath;
explicit Value(long long val = 0) : valueType(INT), intvalue(val), tokvalue(nullptr), floatValue(0.0), moveKind(NonMovedVariable), varvalue(val), condition(0), varId(0U), conditional(false), inconclusive(false), defaultArg(false), valueKind(ValueKind::Possible) {}
explicit Value(long long val = 0) : valueType(INT), intvalue(val), tokvalue(nullptr), floatValue(0.0), moveKind(NonMovedVariable), varvalue(val), condition(nullptr), varId(0U), conditional(false), inconclusive(false), defaultArg(false), valueKind(ValueKind::Possible) {}
Value(const Token *c, long long val);
bool operator==(const Value &rhs) const {