Merge pull request #364 from Dmitry-Me/tempVariablesAndBetterNames

Shorten code by using temp variables, cleanup variable names.
This commit is contained in:
Daniel Marjamäki 2014-07-16 15:22:11 +02:00
commit 51c2245a07
2 changed files with 24 additions and 21 deletions

View File

@ -1243,11 +1243,11 @@ void CheckBufferOverrun::checkStructVariable()
} }
// Goto end of statement. // Goto end of statement.
const Token *CheckTok = nullptr; const Token *checkTok = nullptr;
while (tok3 && tok3 != func_scope->classEnd) { while (tok3 && tok3 != func_scope->classEnd) {
// End of statement. // End of statement.
if (tok3->str() == ";") { if (tok3->str() == ";") {
CheckTok = tok3; checkTok = tok3;
break; break;
} }
@ -1257,7 +1257,7 @@ void CheckBufferOverrun::checkStructVariable()
// Function implementation.. // Function implementation..
if (Token::simpleMatch(tok3, ") {")) { if (Token::simpleMatch(tok3, ") {")) {
CheckTok = tok3->tokAt(2); checkTok = tok3->tokAt(2);
break; break;
} }
@ -1267,7 +1267,7 @@ void CheckBufferOverrun::checkStructVariable()
if (!tok3) if (!tok3)
break; break;
if (!CheckTok) if (!checkTok)
continue; continue;
// Check variable usage.. // Check variable usage..
@ -1278,7 +1278,7 @@ void CheckBufferOverrun::checkStructVariable()
varnames += (k == 0 ? "" : ".") + varname[k]; varnames += (k == 0 ? "" : ".") + varname[k];
temp.varname(varnames); 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(); const std::size_t functions = symbolDatabase->functionScopes.size();
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];
const Function * j = scope->function; const Function * function = scope->function;
if (j) { if (function) {
// only looking for destructors // only looking for destructors
if (j->type == Function::eDestructor) { if (function->type == Function::eDestructor) {
// Inspect this destructor. // Inspect this destructor.
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
// Skip try blocks // Skip try blocks
@ -103,7 +103,7 @@ void CheckExceptionSafety::deallocThrow()
const unsigned int varid(tok->varId()); const unsigned int varid(tok->varId());
// Token where throw occurs // Token where throw occurs
const Token *ThrowToken = nullptr; const Token *throwToken = nullptr;
// is there a throw after the deallocation? // is there a throw after the deallocation?
const Token* const end2 = tok->scope()->classEnd; const Token* const end2 = tok->scope()->classEnd;
@ -114,13 +114,13 @@ void CheckExceptionSafety::deallocThrow()
deallocThrowError(tok2, tok->str()); deallocThrowError(tok2, tok->str());
break; break;
} }
ThrowToken = tok2; throwToken = tok2;
} }
// Variable is assigned -> Bail out // Variable is assigned -> Bail out
else if (Token::Match(tok2, "%varid% =", varid)) { 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. 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()); deallocThrowError(throwToken, tok2->str());
break; break;
} }
// Variable passed to function. Assume it becomes assigned -> Bail out // 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(); const std::size_t functions = symbolDatabase->functionScopes.size();
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];
const Function* function = scope->function;
if (!function)
continue;
// check noexcept functions // check noexcept functions
if (scope->function && scope->function->isNoExcept && if (function->isNoExcept &&
(!scope->function->noexceptArg || scope->function->noexceptArg->str() == "true")) { (!function->noexceptArg || function->noexceptArg->str() == "true")) {
const Token *throws = functionThrows(scope->function); const Token *throws = functionThrows(function);
if (throws) if (throws)
noexceptThrowError(throws); noexceptThrowError(throws);
} }
// check throw() functions // check throw() functions
else if (scope->function && scope->function->isThrow && !scope->function->throwArg) { else if (function->isThrow && !function->throwArg) {
const Token *throws = functionThrows(scope->function); const Token *throws = functionThrows(function);
if (throws) if (throws)
nothrowThrowError(throws); nothrowThrowError(throws);
} }
// check __attribute__((nothrow)) functions // check __attribute__((nothrow)) functions
else if (scope->function && scope->function->isAttributeNothrow()) { else if (function->isAttributeNothrow()) {
const Token *throws = functionThrows(scope->function); const Token *throws = functionThrows(function);
if (throws) if (throws)
nothrowAttributeThrowError(throws); nothrowAttributeThrowError(throws);
} }
// check __declspec(nothrow) functions // check __declspec(nothrow) functions
else if (scope->function && scope->function->isDeclspecNothrow()) { else if (function->isDeclspecNothrow()) {
const Token *throws = functionThrows(scope->function); const Token *throws = functionThrows(function);
if (throws) if (throws)
nothrowDeclspecThrowError(throws); nothrowDeclspecThrowError(throws);
} }