Added some nullpointer-checks and removed some redundant ones based on VS2012 code analysis results.
This commit is contained in:
parent
3c14e4b52a
commit
508e9394d3
|
@ -800,7 +800,7 @@ void CheckBufferOverrun::arrayIndexInForLoop(const Token *tok, const ArrayInfo &
|
|||
}
|
||||
|
||||
if (max_value > size) {
|
||||
if (tok3->strAt(1) == ")") {
|
||||
if (tok3 && tok3->strAt(1) == ")") {
|
||||
bool usedInArray = false;
|
||||
for (const Token *loopTok = tok3->tokAt(2); loopTok->str() != "}" ; loopTok = loopTok->next()) {
|
||||
if (loopTok->varId() == arrayInfo.varid() && loopTok->tokAt(2)->varId() == counter_varid)
|
||||
|
@ -834,7 +834,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
|
||||
const unsigned char varc = static_cast<unsigned char>(varname.empty() ? 0U : (varname.size() - 1) * 2U);
|
||||
|
||||
if (tok && tok->str() == "return") {
|
||||
if (tok->str() == "return") {
|
||||
tok = tok->next();
|
||||
if (!tok)
|
||||
return;
|
||||
|
@ -989,7 +989,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
std::size_t charactersAppend = 0;
|
||||
const Token *tok2 = tok;
|
||||
|
||||
while (tok2 && Token::Match(tok2, strcatPattern.c_str(), varid)) {
|
||||
while (Token::Match(tok2, strcatPattern.c_str(), varid)) {
|
||||
charactersAppend += Token::getStrLength(tok2->tokAt(4 + varc));
|
||||
if (charactersAppend >= static_cast<std::size_t>(total_size)) {
|
||||
bufferOverrunError(tok2);
|
||||
|
@ -1718,8 +1718,7 @@ void CheckBufferOverrun::checkSprintfCall(const Token *tok, const MathLib::bigin
|
|||
//---------------------------------------------------------------------------
|
||||
void CheckBufferOverrun::checkBufferAllocatedWithStrlen()
|
||||
{
|
||||
const char pattern[] = "%var% = new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc";
|
||||
for (const Token *tok = Token::findmatch(_tokenizer->tokens(), pattern); tok; tok = Token::findmatch(tok->next(),pattern)) {
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
unsigned int dstVarId;
|
||||
unsigned int srcVarId;
|
||||
|
||||
|
@ -1754,9 +1753,9 @@ void CheckBufferOverrun::checkBufferAllocatedWithStrlen()
|
|||
tok->strAt(4).find("%s") != std::string::npos) {
|
||||
bufferOverrunError(tok);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!tok)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -332,9 +332,6 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
|
|||
int level = 0;
|
||||
|
||||
for (; ftok != func.functionScope->classEnd; ftok = ftok->next()) {
|
||||
if (!ftok->next())
|
||||
break;
|
||||
|
||||
// Class constructor.. initializing variables like this
|
||||
// clKalle::clKalle() : var(value) { }
|
||||
if (initList) {
|
||||
|
|
|
@ -260,13 +260,13 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
|||
if (!Token::Match(tok, "[;{}]") || Token::Match(tok->next(), "[;{}]"))
|
||||
continue;
|
||||
tok = tok->next();
|
||||
if (tok == endToken)
|
||||
if (!tok || tok == endToken)
|
||||
break;
|
||||
|
||||
// parse statement
|
||||
|
||||
// assignment..
|
||||
if (tok && tok->varId() && Token::Match(tok, "%var% =")) {
|
||||
if (tok->varId() && Token::Match(tok, "%var% =")) {
|
||||
// taking address of another variable..
|
||||
if (Token::Match(tok->next(), "= %var% [+;]")) {
|
||||
if (tok->tokAt(2)->varId() != tok->varId()) {
|
||||
|
|
|
@ -2095,7 +2095,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
|
|||
noerr |= Token::simpleMatch(first, "alloc ; if return ; dealloc; }");
|
||||
|
||||
// Unhandled case..
|
||||
if (! noerr) {
|
||||
if (!noerr && tok) {
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "inconclusive leak of " << varname << ": ";
|
||||
errmsg << tok->stringifyList(false, false, false, false, false, 0, 0);
|
||||
|
@ -2282,7 +2282,7 @@ void CheckMemoryLeakInClass::check()
|
|||
const Token *tok = var->typeStartToken();
|
||||
if (tok->str() == "const")
|
||||
tok = tok->next();
|
||||
if (tok && tok->isStandardType()) {
|
||||
if (tok->isStandardType()) {
|
||||
if (var->isPrivate())
|
||||
checkPublicFunctions(&(*scope), var->nameToken());
|
||||
|
||||
|
|
|
@ -759,7 +759,7 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
|
|||
tok2 = tok2->previous();
|
||||
}
|
||||
}
|
||||
if (Token::Match(tok2, "[?:]") || tok2->varId() == varid)
|
||||
if (!tok2 || Token::Match(tok2, "[?:]") || tok2->varId() == varid)
|
||||
continue;
|
||||
|
||||
// unknown : this is set by isPointerDeRef if it is
|
||||
|
|
|
@ -246,7 +246,7 @@ void CheckOther::clarifyStatement()
|
|||
|
||||
if (Token::Match(tok2, "[{};]")) {
|
||||
tok = tok->tokAt(2);
|
||||
while (tok) {
|
||||
for (;;) {
|
||||
if (tok->str() == "[")
|
||||
tok = tok->link()->next();
|
||||
|
||||
|
|
|
@ -1232,7 +1232,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
|||
return true;
|
||||
|
||||
// variable is seen..
|
||||
if (tok && tok->varId() == var.varId()) {
|
||||
if (tok->varId() == var.varId()) {
|
||||
// Use variable
|
||||
if (!suppressErrors && isVariableUsage(tok, var.isPointer()))
|
||||
uninitvarError(tok, tok->str());
|
||||
|
|
Loading…
Reference in New Issue