Fix FN variableScope (#5273)
Co-authored-by: chrchr-github <chrchr@github>
This commit is contained in:
parent
4452ae6d09
commit
931a59a724
|
@ -1074,6 +1074,7 @@ bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& us
|
|||
if (var->isArrayOrPointer()) {
|
||||
int argn{};
|
||||
if (const Token* ftok = getTokenArgumentFunction(tok, argn)) { // var passed to function?
|
||||
if (ftok->next()->astParent()) { // return value used?
|
||||
if (ftok->function() && Function::returnsPointer(ftok->function()))
|
||||
return false;
|
||||
const std::string ret = mSettings->library.returnValueType(ftok); // assume that var is returned
|
||||
|
@ -1083,6 +1084,7 @@ bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& us
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1656,6 +1656,16 @@ private:
|
|||
" printf(\"%d: %s\\n\", err, msg);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("char* g(char* dst, const char* src);\n"
|
||||
"void f(int err, const char* src) {\n"
|
||||
" const char* msg = \"Success\";\n"
|
||||
" char buf[42];\n"
|
||||
" if (err != 0)\n"
|
||||
" g(buf, src);\n"
|
||||
" printf(\"%d: %s\\n\", err, msg);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (style) The scope of the variable 'buf' can be reduced.\n", errout.str());
|
||||
}
|
||||
|
||||
#define checkOldStylePointerCast(code) checkOldStylePointerCast_(code, __FILE__, __LINE__)
|
||||
|
|
Loading…
Reference in New Issue