Skip to content

Commit 0d4b439

Browse files
Fix FP with embedded zeros (#4226)
* Partial fix for #11137 FN: invalidFunctionArgStr printf argument * Typo * Remove <strz>, suppressions * Add suppresion, remove <strz> * Add suppressions * Fix FP with embedded zeros * Merge
1 parent de2509f commit 0d4b439

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/checkfunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void CheckFunctions::invalidFunctionUsage()
174174
const Token* strTok = varTok->getValueTokenMinStrSize(mSettings);
175175
if (strTok) {
176176
const int strSize = Token::getStrArraySize(strTok);
177-
if (strSize > count)
177+
if (strSize > count && strTok->str().find('\0') == std::string::npos)
178178
invalidFunctionArgStrError(argtok, functionToken->str(), argnr);
179179
}
180180
}

test/testfunctions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,12 @@ class TestFunctions : public TestFixture {
729729
" strcat(dest, if_name);\n"
730730
"}\n");
731731
ASSERT_EQUALS("", errout.str());
732+
733+
check("int f() {\n"
734+
" const char c[3] = \"ab\\0\";\n"
735+
" return strlen(c);\n"
736+
"}\n");
737+
ASSERT_EQUALS("", errout.str());
732738
}
733739

734740
void mathfunctionCall_sqrt() {

0 commit comments

Comments
 (0)