From 402d0c565ffc2f2281cb324c90ef2bba30400b95 Mon Sep 17 00:00:00 2001 From: rikardfalkeborn Date: Fri, 19 Oct 2018 07:48:47 +0200 Subject: [PATCH] Fix false positive: Invalid string argument with array (#1439) --- 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 7634492fe..5184d0ecb 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -130,7 +130,7 @@ void CheckFunctions::invalidFunctionUsage() if (Token::Match(argtok, "& %var% !![") && argtok->next() && argtok->next()->valueType()) { const ValueType * valueType = argtok->next()->valueType(); const Variable * variable = argtok->next()->variable(); - if (valueType->type == ValueType::Type::CHAR && !variable->isGlobal() && + if (valueType->type == ValueType::Type::CHAR && !variable->isArray() && !variable->isGlobal() && (!argtok->next()->hasKnownValue() || argtok->next()->getValue(0) == nullptr)) { invalidFunctionArgStrError(argtok, functionToken->str(), argnr); } diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 4d0eb3c7f..e7141daf8 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -537,6 +537,12 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("size_t f() {\n" + " char ca[] = \"asdf\";\n" + " return strlen((char*) &ca);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // #5225 check("int main(void)\n" "{\n"