Fix false positive: Invalid string argument with array (#1439)

This commit is contained in:
rikardfalkeborn 2018-10-19 07:48:47 +02:00 committed by Daniel Marjamäki
parent 40cb9cb1bc
commit 402d0c565f
2 changed files with 7 additions and 1 deletions

View File

@ -130,7 +130,7 @@ void CheckFunctions::invalidFunctionUsage()
if (Token::Match(argtok, "& %var% !![") && argtok->next() && argtok->next()->valueType()) { if (Token::Match(argtok, "& %var% !![") && argtok->next() && argtok->next()->valueType()) {
const ValueType * valueType = argtok->next()->valueType(); const ValueType * valueType = argtok->next()->valueType();
const Variable * variable = argtok->next()->variable(); 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)) { (!argtok->next()->hasKnownValue() || argtok->next()->getValue(0) == nullptr)) {
invalidFunctionArgStrError(argtok, functionToken->str(), argnr); invalidFunctionArgStrError(argtok, functionToken->str(), argnr);
} }

View File

@ -537,6 +537,12 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("size_t f() {\n"
" char ca[] = \"asdf\";\n"
" return strlen((char*) &ca);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #5225 // #5225
check("int main(void)\n" check("int main(void)\n"
"{\n" "{\n"