Skip to content

Commit 044a4cf

Browse files
Update checkother.cpp
1 parent bd5ff18 commit 044a4cf

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,17 @@ static bool isCastToInteger(const Token* tok)
18381838
return tok && tok->isCast() && tok->valueType() && tok->valueType()->isIntegral() && tok->valueType()->pointer == 0;
18391839
}
18401840

1841+
static const Function* getEnclosingFunction(const Variable* var)
1842+
{
1843+
if (var->isArgument())
1844+
return var->scope()->function;
1845+
const Scope* scope = var->scope();
1846+
while (scope && scope->type != ScopeType::eFunction) {
1847+
scope = scope->nestedIn;
1848+
}
1849+
return scope ? scope->function : nullptr;
1850+
}
1851+
18411852
void CheckOther::checkConstPointer()
18421853
{
18431854
if (!mSettings->severity.isEnabled(Severity::style) &&
@@ -1917,7 +1928,7 @@ void CheckOther::checkConstPointer()
19171928
continue;
19181929
int argn = -1;
19191930
if (Token::simpleMatch(gparent, "return")) {
1920-
const Function* function = gparent->scope()->function;
1931+
const Function* function = getEnclosingFunction(var);
19211932
if (function && (!Function::returnsReference(function) || Function::returnsConst(function)))
19221933
continue;
19231934
}

0 commit comments

Comments
 (0)