diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index f6799d199e7..7611ea7eee4 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -153,7 +153,7 @@ void CheckFunctions::invalidFunctionUsage() // Is non-null terminated local variable of type char (e.g. char buf[] = {'x'};) ? if (variable && variable->isLocal() && valueType && (valueType->type == ValueType::Type::CHAR || valueType->type == ValueType::Type::WCHAR_T) - && !isVariablesChanged(variable->declEndToken(), functionToken, 0 /*indirect*/, { variable }, *mSettings)) { + && !isVariablesChanged(variable->declEndToken(), functionToken, valueType->pointer, { variable }, *mSettings)) { const Token* varTok = variable->declEndToken(); MathLib::bigint count = -1; // Find out explicitly set count, e.g.: char buf[3] = {...}. Variable 'count' is set to 3 then. if (varTok && Token::simpleMatch(varTok->astOperand1(), "[")) diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index c3fe10afe39..8bbd3d92c6b 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -761,6 +761,13 @@ class TestFunctions : public TestFixture { "}\n"); ASSERT_EQUALS("", errout_str()); + check("char* f() {\n" // #14715 + " char a[3] = { 'a', 'b', 'c' };\n" + " *a = 0;\n" + " return strdup(a);\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); + check("size_t f() { wchar_t x = L'x'; return wcslen(&x); }"); ASSERT_EQUALS("[test.cpp:1:46]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str());