Fix FP with complex array size expression (#4225)

* Partial fix for #11137 FN: invalidFunctionArgStr printf argument

* Typo

* Remove <strz>, suppressions

* Add suppresion, remove <strz>

* Add suppressions

* Fix FP with complex array size expression
This commit is contained in:
chrchr-github 2022-06-21 00:12:11 +02:00 committed by GitHub
parent 5b9fa9657d
commit de2509f1ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -144,9 +144,9 @@ void CheckFunctions::invalidFunctionUsage()
&& valueType && (valueType->type == ValueType::Type::CHAR || valueType->type == ValueType::Type::WCHAR_T)) {
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->previous(), "]"))
if (varTok && Token::simpleMatch(varTok->astOperand1(), "["))
{
const Token* const countTok = varTok->tokAt(-2);
const Token* const countTok = varTok->astOperand1()->astOperand2();
if (countTok && countTok->hasKnownIntValue())
count = countTok->getKnownIntValue();
}

View File

@ -723,6 +723,12 @@ private:
" return wcslen(c);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required.\n", errout.str());
check("void f(char* dest) {\n"
" char if_name[(IF_NAMESIZE > 21 ? IF_NAMESIZE : 21) + 1] = \"%\";\n"
" strcat(dest, if_name);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void mathfunctionCall_sqrt() {