Refactorization: Removed redundant %any% patterns.
This commit is contained in:
parent
0052896c41
commit
940d569980
|
@ -819,7 +819,7 @@ void CheckClass::initializationListUsage()
|
|||
break;
|
||||
if (Token::Match(tok, "try|do {"))
|
||||
break;
|
||||
if (Token::Match(tok, "%var% = %any%") && tok->strAt(-1) != "*") {
|
||||
if (Token::Match(tok, "%var% =") && tok->strAt(-1) != "*") {
|
||||
const Variable* var = tok->variable();
|
||||
if (var && var->scope() == owner && !var->isStatic()) {
|
||||
if (var->isPointer() || var->isReference() || (!var->type() && !var->isStlStringType() && !(Token::Match(var->typeStartToken(), "std :: %type% <") && !Token::simpleMatch(var->typeStartToken()->linkAt(3), "> ::"))))
|
||||
|
@ -991,7 +991,7 @@ void CheckClass::checkMemset()
|
|||
for (std::size_t i = 0; i < functions; ++i) {
|
||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
||||
if (Token::Match(tok, "memset|memcpy|memmove ( %any%")) {
|
||||
if (Token::Match(tok, "memset|memcpy|memmove (")) {
|
||||
const Token* arg1 = tok->tokAt(2);
|
||||
const Token* arg3 = arg1->nextArgument();
|
||||
if (arg3)
|
||||
|
|
|
@ -222,7 +222,7 @@ void CheckFunctions::checkMathFunctions()
|
|||
mathfunctionCallWarning(tok, 2);
|
||||
}
|
||||
// fmod ( x , y) If y is zero, then either a range error will occur or the function will return zero (implementation-defined).
|
||||
else if (Token::Match(tok, "fmod|fmodf|fmodl ( %any%")) {
|
||||
else if (Token::Match(tok, "fmod|fmodf|fmodl (")) {
|
||||
const Token* nextArg = tok->tokAt(2)->nextArgument();
|
||||
if (nextArg && nextArg->isNumber() && MathLib::isNullValue(nextArg->str()))
|
||||
mathfunctionCallWarning(tok, 2);
|
||||
|
|
|
@ -498,7 +498,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
|||
bool scanf_s = false;
|
||||
int formatStringArgNo = -1;
|
||||
|
||||
if (Token::Match(tok->next(), "( %any%") && _settings->library.formatstr_function(tok->str())) {
|
||||
if (tok->strAt(1) == "(" && _settings->library.formatstr_function(tok->str())) {
|
||||
const std::map<int, Library::ArgumentChecks>& argumentChecks = _settings->library.argumentChecks.at(tok->str());
|
||||
for (std::map<int, Library::ArgumentChecks>::const_iterator i = argumentChecks.cbegin(); i != argumentChecks.cend(); ++i) {
|
||||
if (i->second.formatstr) {
|
||||
|
|
|
@ -2094,7 +2094,7 @@ void CheckMemoryLeakInFunction::checkReallocUsage()
|
|||
// Search for the "var = realloc(var, 100" pattern within this function
|
||||
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||
if (tok->varId() > 0 &&
|
||||
Token::Match(tok, "%name% = realloc|g_try_realloc ( %name% , %any%") &&
|
||||
Token::Match(tok, "%name% = realloc|g_try_realloc ( %name% ,") &&
|
||||
tok->varId() == tok->tokAt(4)->varId() &&
|
||||
isNoArgument(symbolDatabase, tok->varId())) {
|
||||
// Check that another copy of the pointer wasn't saved earlier in the function
|
||||
|
@ -2113,7 +2113,7 @@ void CheckMemoryLeakInFunction::checkReallocUsage()
|
|||
|
||||
memleakUponReallocFailureError(tok, tok->str());
|
||||
} else if (tok->next()->varId() > 0 &&
|
||||
(Token::Match(tok, "* %name% = realloc|g_try_realloc ( * %name% , %any%") &&
|
||||
(Token::Match(tok, "* %name% = realloc|g_try_realloc ( * %name% ,") &&
|
||||
tok->next()->varId() == tok->tokAt(6)->varId()) &&
|
||||
isNoArgument(symbolDatabase, tok->next()->varId())) {
|
||||
// Check that another copy of the pointer wasn't saved earlier in the function
|
||||
|
|
|
@ -921,7 +921,7 @@ void CheckOther::checkSuspiciousEqualityComparison()
|
|||
// for (i = 0; i < 10; i == a)
|
||||
if (Token::Match(openParen->next(), "%name% =="))
|
||||
suspiciousEqualityComparisonError(openParen->tokAt(2));
|
||||
if (Token::Match(closeParen->tokAt(-2), "== %any%"))
|
||||
if (closeParen->strAt(-2) == "==")
|
||||
suspiciousEqualityComparisonError(closeParen->tokAt(-2));
|
||||
|
||||
// Skip over for() loop conditions because "for (;running==1;)"
|
||||
|
@ -1292,7 +1292,7 @@ bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& us
|
|||
if (Token::Match(tok, "& %varid%", var->declarationId())) // Taking address of variable
|
||||
return false;
|
||||
|
||||
if (Token::Match(tok, "%varid% = %any%", var->declarationId()))
|
||||
if (Token::Match(tok, "%varid% =", var->declarationId()))
|
||||
bFirstAssignment = true;
|
||||
|
||||
if (!bFirstAssignment && Token::Match(tok, "* %varid%", var->declarationId())) // dereferencing means access to previous content
|
||||
|
@ -1793,8 +1793,8 @@ void CheckOther::checkInvalidFree()
|
|||
|
||||
// If a variable that was previously assigned a newly-allocated memory location is
|
||||
// added or subtracted from when used to free the memory, report an error.
|
||||
else if (Token::Match(tok, "free|g_free|delete ( %any% +|- %any%") ||
|
||||
Token::Match(tok, "delete [ ] ( %any% +|- %any%") ||
|
||||
else if (Token::Match(tok, "free|g_free|delete ( %any% +|-") ||
|
||||
Token::Match(tok, "delete [ ] ( %any% +|-") ||
|
||||
Token::Match(tok, "delete %any% +|- %any%")) {
|
||||
|
||||
const int varIndex = tok->strAt(1) == "(" ? 2 :
|
||||
|
|
|
@ -193,7 +193,7 @@ void CheckStl::iterators()
|
|||
}
|
||||
|
||||
// Reassign the iterator
|
||||
else if (Token::Match(tok2, "%varid% = %any%", iteratorId)) {
|
||||
else if (Token::Match(tok2, "%varid% =", iteratorId)) {
|
||||
// Assume that the iterator becomes valid.
|
||||
// TODO: add checking that checks if the iterator becomes valid or not
|
||||
validatingToken = Token::findmatch(tok2->tokAt(2), "[;)]");
|
||||
|
|
Loading…
Reference in New Issue