Fix #11179 FP invalidFunctionArgStr (#4264)

This commit is contained in:
chrchr-github 2022-07-11 22:58:19 +02:00 committed by GitHub
parent f9337b725b
commit 8fc75402a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -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(), "["))

View File

@ -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() {