Skip to content

Commit de2509f

Browse files
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
1 parent 5b9fa96 commit de2509f

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

lib/checkfunctions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ void CheckFunctions::invalidFunctionUsage()
144144
&& valueType && (valueType->type == ValueType::Type::CHAR || valueType->type == ValueType::Type::WCHAR_T)) {
145145
const Token* varTok = variable->declEndToken();
146146
auto count = -1; // Find out explicitly set count, e.g.: char buf[3] = {...}. Variable 'count' is set to 3 then.
147-
if (varTok && Token::simpleMatch(varTok->previous(), "]"))
147+
if (varTok && Token::simpleMatch(varTok->astOperand1(), "["))
148148
{
149-
const Token* const countTok = varTok->tokAt(-2);
149+
const Token* const countTok = varTok->astOperand1()->astOperand2();
150150
if (countTok && countTok->hasKnownIntValue())
151151
count = countTok->getKnownIntValue();
152152
}

test/testfunctions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,12 @@ class TestFunctions : public TestFixture {
723723
" return wcslen(c);\n"
724724
"}\n");
725725
ASSERT_EQUALS("[test.cpp:3]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required.\n", errout.str());
726+
727+
check("void f(char* dest) {\n"
728+
" char if_name[(IF_NAMESIZE > 21 ? IF_NAMESIZE : 21) + 1] = \"%\";\n"
729+
" strcat(dest, if_name);\n"
730+
"}\n");
731+
ASSERT_EQUALS("", errout.str());
726732
}
727733

728734
void mathfunctionCall_sqrt() {

0 commit comments

Comments
 (0)