Skip to content

Commit 13234a7

Browse files
committed
Shorten code by using temp variables, cleanup variable names.
1 parent e057e96 commit 13234a7

2 files changed

Lines changed: 24 additions & 21 deletions

File tree

lib/checkbufferoverrun.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,11 +1243,11 @@ void CheckBufferOverrun::checkStructVariable()
12431243
}
12441244

12451245
// Goto end of statement.
1246-
const Token *CheckTok = nullptr;
1246+
const Token *checkTok = nullptr;
12471247
while (tok3 && tok3 != func_scope->classEnd) {
12481248
// End of statement.
12491249
if (tok3->str() == ";") {
1250-
CheckTok = tok3;
1250+
checkTok = tok3;
12511251
break;
12521252
}
12531253

@@ -1257,7 +1257,7 @@ void CheckBufferOverrun::checkStructVariable()
12571257

12581258
// Function implementation..
12591259
if (Token::simpleMatch(tok3, ") {")) {
1260-
CheckTok = tok3->tokAt(2);
1260+
checkTok = tok3->tokAt(2);
12611261
break;
12621262
}
12631263

@@ -1267,7 +1267,7 @@ void CheckBufferOverrun::checkStructVariable()
12671267
if (!tok3)
12681268
break;
12691269

1270-
if (!CheckTok)
1270+
if (!checkTok)
12711271
continue;
12721272

12731273
// Check variable usage..
@@ -1278,7 +1278,7 @@ void CheckBufferOverrun::checkStructVariable()
12781278
varnames += (k == 0 ? "" : ".") + varname[k];
12791279

12801280
temp.varname(varnames);
1281-
checkScope(CheckTok, varname, temp);
1281+
checkScope(checkTok, varname, temp);
12821282
}
12831283
}
12841284
}

lib/checkexceptionsafety.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ void CheckExceptionSafety::destructors()
3838
const std::size_t functions = symbolDatabase->functionScopes.size();
3939
for (std::size_t i = 0; i < functions; ++i) {
4040
const Scope * scope = symbolDatabase->functionScopes[i];
41-
const Function * j = scope->function;
42-
if (j) {
41+
const Function * function = scope->function;
42+
if (function) {
4343
// only looking for destructors
44-
if (j->type == Function::eDestructor) {
44+
if (function->type == Function::eDestructor) {
4545
// Inspect this destructor.
4646
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
4747
// Skip try blocks
@@ -103,7 +103,7 @@ void CheckExceptionSafety::deallocThrow()
103103
const unsigned int varid(tok->varId());
104104

105105
// Token where throw occurs
106-
const Token *ThrowToken = nullptr;
106+
const Token *throwToken = nullptr;
107107

108108
// is there a throw after the deallocation?
109109
const Token* const end2 = tok->scope()->classEnd;
@@ -114,13 +114,13 @@ void CheckExceptionSafety::deallocThrow()
114114
deallocThrowError(tok2, tok->str());
115115
break;
116116
}
117-
ThrowToken = tok2;
117+
throwToken = tok2;
118118
}
119119

120120
// Variable is assigned -> Bail out
121121
else if (Token::Match(tok2, "%varid% =", varid)) {
122-
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.
123-
deallocThrowError(ThrowToken, tok2->str());
122+
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.
123+
deallocThrowError(throwToken, tok2->str());
124124
break;
125125
}
126126
// Variable passed to function. Assume it becomes assigned -> Bail out
@@ -236,32 +236,35 @@ void CheckExceptionSafety::nothrowThrows()
236236
const std::size_t functions = symbolDatabase->functionScopes.size();
237237
for (std::size_t i = 0; i < functions; ++i) {
238238
const Scope * scope = symbolDatabase->functionScopes[i];
239+
const Function* function = scope->function;
240+
if (!function)
241+
continue;
239242

240243
// check noexcept functions
241-
if (scope->function && scope->function->isNoExcept &&
242-
(!scope->function->noexceptArg || scope->function->noexceptArg->str() == "true")) {
243-
const Token *throws = functionThrows(scope->function);
244+
if (function->isNoExcept &&
245+
(!function->noexceptArg || function->noexceptArg->str() == "true")) {
246+
const Token *throws = functionThrows(function);
244247
if (throws)
245248
noexceptThrowError(throws);
246249
}
247250

248251
// check throw() functions
249-
else if (scope->function && scope->function->isThrow && !scope->function->throwArg) {
250-
const Token *throws = functionThrows(scope->function);
252+
else if (function->isThrow && !function->throwArg) {
253+
const Token *throws = functionThrows(function);
251254
if (throws)
252255
nothrowThrowError(throws);
253256
}
254257

255258
// check __attribute__((nothrow)) functions
256-
else if (scope->function && scope->function->isAttributeNothrow()) {
257-
const Token *throws = functionThrows(scope->function);
259+
else if (function->isAttributeNothrow()) {
260+
const Token *throws = functionThrows(function);
258261
if (throws)
259262
nothrowAttributeThrowError(throws);
260263
}
261264

262265
// check __declspec(nothrow) functions
263-
else if (scope->function && scope->function->isDeclspecNothrow()) {
264-
const Token *throws = functionThrows(scope->function);
266+
else if (function->isDeclspecNothrow()) {
267+
const Token *throws = functionThrows(function);
265268
if (throws)
266269
nothrowDeclspecThrowError(throws);
267270
}

0 commit comments

Comments
 (0)