use nullptr in lib/checkmemoryleak.cpp

This commit is contained in:
Daniel Marjamäki 2014-02-15 16:17:25 +01:00
parent 68119f0230
commit 209dffbe1b
1 changed files with 21 additions and 21 deletions

View File

@ -48,7 +48,7 @@ static unsigned int countParameters(const Token *tok)
return 0; return 0;
unsigned int numpar = 1; unsigned int numpar = 1;
while (NULL != (tok = tok->nextArgument())) while (nullptr != (tok = tok->nextArgument()))
numpar++; numpar++;
return numpar; return numpar;
@ -121,7 +121,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
// * var = strndup("hello", 3); // * var = strndup("hello", 3);
if (tok2 && tok2->str() == "(") { if (tok2 && tok2->str() == "(") {
tok2 = tok2->link(); tok2 = tok2->link();
tok2 = tok2 ? tok2->next() : NULL; tok2 = tok2 ? tok2->next() : nullptr;
} }
if (! tok2) if (! tok2)
return No; return No;
@ -190,7 +190,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
// User function // User function
const Function* func = tok2->function(); const Function* func = tok2->function();
if (func == NULL) if (func == nullptr)
return No; return No;
// Prevent recursion // Prevent recursion
@ -212,7 +212,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType(const Token *tok
// * var = (char *)realloc(..; // * var = (char *)realloc(..;
if (tok2 && tok2->str() == "(") { if (tok2 && tok2->str() == "(") {
tok2 = tok2->link(); tok2 = tok2->link();
tok2 = tok2 ? tok2->next() : NULL; tok2 = tok2 ? tok2->next() : nullptr;
} }
if (! tok2) if (! tok2)
return No; return No;
@ -420,7 +420,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f
if (varid == 0) if (varid == 0)
return No; return No;
if (this != NULL) { if (this != nullptr) {
// If variable is not local then alloctype shall be "No" // If variable is not local then alloctype shall be "No"
// Todo: there can be false negatives about mismatching allocation/deallocation. // Todo: there can be false negatives about mismatching allocation/deallocation.
// => Generate "alloc ; use ;" if variable is not local? // => Generate "alloc ; use ;" if variable is not local?
@ -643,11 +643,11 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
if (numpar == 0) { if (numpar == 0) {
// Taking return value => it is not a noreturn function // Taking return value => it is not a noreturn function
if (tok->strAt(-1) == "=") if (tok->strAt(-1) == "=")
return NULL; return nullptr;
// Function is not noreturn // Function is not noreturn
if (notnoreturn.find(funcname) != notnoreturn.end()) if (notnoreturn.find(funcname) != notnoreturn.end())
return NULL; return nullptr;
return "callfunc"; return "callfunc";
} }
@ -1499,7 +1499,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) const
} }
// Main inner simplification loop // Main inner simplification loop
for (Token *tok2 = tok; tok2; tok2 = tok2 ? tok2->next() : NULL) { for (Token *tok2 = tok; tok2; tok2 = tok2 ? tok2->next() : nullptr) {
// Delete extra ";" // Delete extra ";"
while (Token::Match(tok2, "[;{}] ;")) { while (Token::Match(tok2, "[;{}] ;")) {
tok2->deleteNext(); tok2->deleteNext();
@ -1994,7 +1994,7 @@ const Token *CheckMemoryLeakInFunction::findleak(const Token *tokens)
{ {
const Token *result; const Token *result;
if ((result = Token::findsimplematch(tokens, "loop alloc ;")) != NULL) { if ((result = Token::findsimplematch(tokens, "loop alloc ;")) != nullptr) {
return result; return result;
} }
@ -2002,25 +2002,25 @@ const Token *CheckMemoryLeakInFunction::findleak(const Token *tokens)
return tokens->tokAt(3); return tokens->tokAt(3);
} }
if ((result = Token::findmatch(tokens, "alloc ; if|if(var)|ifv return ;")) != NULL) { if ((result = Token::findmatch(tokens, "alloc ; if|if(var)|ifv return ;")) != nullptr) {
return result->tokAt(3); return result->tokAt(3);
} }
if ((result = Token::findmatch(tokens, "alloc ; alloc|assign|return callfunc| ;")) != NULL) { if ((result = Token::findmatch(tokens, "alloc ; alloc|assign|return callfunc| ;")) != nullptr) {
return result->tokAt(2); return result->tokAt(2);
} }
if ((result = Token::findsimplematch(tokens, "; alloc ; if assign ;")) != NULL) { if ((result = Token::findsimplematch(tokens, "; alloc ; if assign ;")) != nullptr) {
return result->tokAt(4); return result->tokAt(4);
} }
if (((result = Token::findsimplematch(tokens, "; alloc ; if dealloc ; }")) != NULL) && if (((result = Token::findsimplematch(tokens, "; alloc ; if dealloc ; }")) != nullptr) &&
!result->tokAt(7)) { !result->tokAt(7)) {
return result->tokAt(6); return result->tokAt(6);
} }
if ((result = Token::findsimplematch(tokens, "alloc ; }")) != NULL) { if ((result = Token::findsimplematch(tokens, "alloc ; }")) != nullptr) {
if (result->tokAt(3) == NULL) if (result->tokAt(3) == nullptr)
return result->tokAt(2); return result->tokAt(2);
} }
@ -2035,7 +2035,7 @@ const Token *CheckMemoryLeakInFunction::findleak(const Token *tokens)
return last; return last;
} }
return NULL; return nullptr;
} }
@ -2052,14 +2052,14 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
Token *tok = getcode(Tok1, callstack, varid, alloctype, dealloctype, classmember, sz); Token *tok = getcode(Tok1, callstack, varid, alloctype, dealloctype, classmember, sz);
//tok->printOut((std::string("Checkmemoryleak: getcode result for: ") + varname).c_str()); //tok->printOut((std::string("Checkmemoryleak: getcode result for: ") + varname).c_str());
const bool use_addr = bool(Token::findsimplematch(tok, "&use") != NULL); const bool use_addr = bool(Token::findsimplematch(tok, "&use") != nullptr);
// Simplify the code and check if freed memory is used.. // Simplify the code and check if freed memory is used..
for (Token *tok2 = tok; tok2; tok2 = tok2->next()) { for (Token *tok2 = tok; tok2; tok2 = tok2->next()) {
while (Token::Match(tok2, "[;{}] ;")) while (Token::Match(tok2, "[;{}] ;"))
tok2->deleteNext(); tok2->deleteNext();
} }
if ((result = Token::findmatch(tok, "[;{}] dealloc ; use_ ;")) != NULL) { if ((result = Token::findmatch(tok, "[;{}] dealloc ; use_ ;")) != nullptr) {
deallocuseError(result->tokAt(3), varname); deallocuseError(result->tokAt(3), varname);
} }
@ -2108,11 +2108,11 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
return; return;
} }
if ((result = findleak(tok)) != NULL) { if ((result = findleak(tok)) != nullptr) {
memoryLeak(result, varname, alloctype); memoryLeak(result, varname, alloctype);
} }
else if (!use_addr && (result = Token::findsimplematch(tok, "dealloc ; dealloc ;")) != NULL) { else if (!use_addr && (result = Token::findsimplematch(tok, "dealloc ; dealloc ;")) != nullptr) {
deallocDeallocError(result->tokAt(2), varname); deallocDeallocError(result->tokAt(2), varname);
} }
@ -2237,7 +2237,7 @@ void CheckMemoryLeakInFunction::check()
for (std::size_t i = 0; i < functions; ++i) { for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i]; const Scope * scope = symbolDatabase->functionScopes[i];
checkScope(scope->classStart->next(), "", 0, scope->functionOf != NULL, 1); checkScope(scope->classStart->next(), "", 0, scope->functionOf != nullptr, 1);
} }
// Check variables.. // Check variables..