Shorten code by using temp variables, cleanup variable names.

This commit is contained in:
Dmitry-Me 2014-07-14 12:20:00 +04:00
parent e057e962e8
commit 13234a7366
2 changed files with 24 additions and 21 deletions

View File

@ -1243,11 +1243,11 @@ void CheckBufferOverrun::checkStructVariable()
}
// Goto end of statement.
const Token *CheckTok = nullptr;
const Token *checkTok = nullptr;
while (tok3 && tok3 != func_scope->classEnd) {
// End of statement.
if (tok3->str() == ";") {
CheckTok = tok3;
checkTok = tok3;
break;
}
@ -1257,7 +1257,7 @@ void CheckBufferOverrun::checkStructVariable()
// Function implementation..
if (Token::simpleMatch(tok3, ") {")) {
CheckTok = tok3->tokAt(2);
checkTok = tok3->tokAt(2);
break;
}
@ -1267,7 +1267,7 @@ void CheckBufferOverrun::checkStructVariable()
if (!tok3)
break;
if (!CheckTok)
if (!checkTok)
continue;
// Check variable usage..
@ -1278,7 +1278,7 @@ void CheckBufferOverrun::checkStructVariable()
varnames += (k == 0 ? "" : ".") + varname[k];
temp.varname(varnames);
checkScope(CheckTok, varname, temp);
checkScope(checkTok, varname, temp);
}
}
}

View File

@ -38,10 +38,10 @@ void CheckExceptionSafety::destructors()
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
const Function * j = scope->function;
if (j) {
const Function * function = scope->function;
if (function) {
// only looking for destructors
if (j->type == Function::eDestructor) {
if (function->type == Function::eDestructor) {
// Inspect this destructor.
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
// Skip try blocks
@ -103,7 +103,7 @@ void CheckExceptionSafety::deallocThrow()
const unsigned int varid(tok->varId());
// Token where throw occurs
const Token *ThrowToken = nullptr;
const Token *throwToken = nullptr;
// is there a throw after the deallocation?
const Token* const end2 = tok->scope()->classEnd;
@ -114,13 +114,13 @@ void CheckExceptionSafety::deallocThrow()
deallocThrowError(tok2, tok->str());
break;
}
ThrowToken = tok2;
throwToken = tok2;
}
// Variable is assigned -> Bail out
else if (Token::Match(tok2, "%varid% =", varid)) {
if (ThrowToken) // For non-inconclusive checking, wait until we find an assignment to it. Otherwise we assume it is safe to leave a dead pointer.
deallocThrowError(ThrowToken, tok2->str());
if (throwToken) // For non-inconclusive checking, wait until we find an assignment to it. Otherwise we assume it is safe to leave a dead pointer.
deallocThrowError(throwToken, tok2->str());
break;
}
// Variable passed to function. Assume it becomes assigned -> Bail out
@ -236,32 +236,35 @@ void CheckExceptionSafety::nothrowThrows()
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
const Function* function = scope->function;
if (!function)
continue;
// check noexcept functions
if (scope->function && scope->function->isNoExcept &&
(!scope->function->noexceptArg || scope->function->noexceptArg->str() == "true")) {
const Token *throws = functionThrows(scope->function);
if (function->isNoExcept &&
(!function->noexceptArg || function->noexceptArg->str() == "true")) {
const Token *throws = functionThrows(function);
if (throws)
noexceptThrowError(throws);
}
// check throw() functions
else if (scope->function && scope->function->isThrow && !scope->function->throwArg) {
const Token *throws = functionThrows(scope->function);
else if (function->isThrow && !function->throwArg) {
const Token *throws = functionThrows(function);
if (throws)
nothrowThrowError(throws);
}
// check __attribute__((nothrow)) functions
else if (scope->function && scope->function->isAttributeNothrow()) {
const Token *throws = functionThrows(scope->function);
else if (function->isAttributeNothrow()) {
const Token *throws = functionThrows(function);
if (throws)
nothrowAttributeThrowError(throws);
}
// check __declspec(nothrow) functions
else if (scope->function && scope->function->isDeclspecNothrow()) {
const Token *throws = functionThrows(scope->function);
else if (function->isDeclspecNothrow()) {
const Token *throws = functionThrows(function);
if (throws)
nothrowDeclspecThrowError(throws);
}