From dd5d3e67c6cf08cf5b377b991c31dcd06c1bbb79 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 11 Jul 2022 11:34:59 +0200 Subject: [PATCH] Fix #11179 FP invalidFunctionArgStr --- lib/checkfunctions.cpp | 3 ++- test/testfunctions.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index e831fb5d8..ed67e1e6e 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -141,7 +141,8 @@ void CheckFunctions::invalidFunctionUsage() const Variable* const variable = argtok->variable(); // 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)) { + && valueType && (valueType->type == ValueType::Type::CHAR || valueType->type == ValueType::Type::WCHAR_T) && + !isVariablesChanged(variable->declEndToken(), functionToken, 0 /*indirect*/, { variable }, mSettings, mTokenizer->isCPP())) { const Token* varTok = variable->declEndToken(); auto 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 1503ae27f..7690311df 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -735,6 +735,14 @@ private: " return strlen(c);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void f(int n) {\n" // #11179 + " char s[8] = \" \";\n" + " n = (n + 1) % 100;\n" + " sprintf(s, \"lwip%02d\", n);\n" + " s[strlen(s)] = ' ';\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void mathfunctionCall_sqrt() {