From 0d4b4394bbeaf7150eaad35c502bbb4bcac66a60 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 21 Jun 2022 13:33:45 +0200 Subject: [PATCH] Fix FP with embedded zeros (#4226) * Partial fix for #11137 FN: invalidFunctionArgStr printf argument * Typo * Remove , suppressions * Add suppresion, remove * Add suppressions * Fix FP with embedded zeros * Merge --- lib/checkfunctions.cpp | 2 +- test/testfunctions.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index 1c0ba58f6..8fdf20d29 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -174,7 +174,7 @@ void CheckFunctions::invalidFunctionUsage() const Token* strTok = varTok->getValueTokenMinStrSize(mSettings); if (strTok) { const int strSize = Token::getStrArraySize(strTok); - if (strSize > count) + if (strSize > count && strTok->str().find('\0') == std::string::npos) invalidFunctionArgStrError(argtok, functionToken->str(), argnr); } } diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 550d869bd..eef345b5d 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -729,6 +729,12 @@ private: " strcat(dest, if_name);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("int f() {\n" + " const char c[3] = \"ab\\0\";\n" + " return strlen(c);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void mathfunctionCall_sqrt() {