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:
parent
5b9fa9657d
commit
de2509f1ac
|
@ -144,9 +144,9 @@ void CheckFunctions::invalidFunctionUsage()
|
||||||
&& valueType && (valueType->type == ValueType::Type::CHAR || valueType->type == ValueType::Type::WCHAR_T)) {
|
&& valueType && (valueType->type == ValueType::Type::CHAR || valueType->type == ValueType::Type::WCHAR_T)) {
|
||||||
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->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())
|
if (countTok && countTok->hasKnownIntValue())
|
||||||
count = countTok->getKnownIntValue();
|
count = countTok->getKnownIntValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -723,6 +723,12 @@ private:
|
||||||
" return wcslen(c);\n"
|
" return wcslen(c);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required.\n", errout.str());
|
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() {
|
void mathfunctionCall_sqrt() {
|
||||||
|
|
Loading…
Reference in New Issue