Fix #11179 FP invalidFunctionArgStr

This commit is contained in:
chrchr 2022-07-11 11:34:59 +02:00
parent 0af441a656
commit dd5d3e67c6
2 changed files with 10 additions and 1 deletions

View File

@ -141,7 +141,8 @@ void CheckFunctions::invalidFunctionUsage()
const Variable* const variable = argtok->variable(); const Variable* const variable = argtok->variable();
// Is non-null terminated local variable of type char (e.g. char buf[] = {'x'};) ? // Is non-null terminated local variable of type char (e.g. char buf[] = {'x'};) ?
if (variable && variable->isLocal() 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(); 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. 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(), "[")) if (varTok && Token::simpleMatch(varTok->astOperand1(), "["))

View File

@ -735,6 +735,14 @@ private:
" return strlen(c);\n" " return strlen(c);\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); 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() { void mathfunctionCall_sqrt() {