diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 22b57edca24..a0d2677ad58 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1074,11 +1074,13 @@ 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->function() && Function::returnsPointer(ftok->function())) - return false; - const std::string ret = mSettings->library.returnValueType(ftok); // assume that var is returned - if (!ret.empty() && ret.back() == '*') - return false; + 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 + if (!ret.empty() && ret.back() == '*') + return false; + } } } } diff --git a/test/testother.cpp b/test/testother.cpp index 8e3799f5251..ed348a18a46 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1656,6 +1656,16 @@ class TestOther : public TestFixture { " 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__)