checkuninitvar.cpp: Use argument direction info from library config. (#1728)

CheckUninitVar::isMemberVariableAssignment uses argument direction
to check for assignment when the member variable is handed over to a
function by reference. Currently implemented for "in" direction. "out"
will be added with another commit.
This commit is contained in:
Sebastian 2019-03-06 19:26:38 +01:00 committed by GitHub
parent ad37664e86
commit 6228ea2266
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -1199,6 +1199,14 @@ bool CheckUninitVar::isMemberVariableAssignment(const Token *tok, const std::str
if (Token::Match(ftok, "%name% (")) {
// check how function handle uninitialized data arguments..
const Function *function = ftok->function();
if (!function && mSettings) {
// Function definition not seen, check if direction is specified in the library configuration
const Library::ArgumentChecks::Direction argDirection = mSettings->library.getArgDirection(ftok, 1 + argumentNumber);
if (argDirection == Library::ArgumentChecks::Direction::DIR_IN)
return false;
}
const Variable *arg = function ? function->getArgumentVar(argumentNumber) : nullptr;
const Token *argStart = arg ? arg->typeStartToken() : nullptr;
while (argStart && argStart->previous() && argStart->previous()->isName())