Fix 11894: FPs knownArgument with sizeof and function pointer (#5396)
This commit is contained in:
parent
37b2e50933
commit
6c0a5a5859
|
@ -3764,11 +3764,17 @@ void CheckOther::checkKnownArgument()
|
|||
mTokenizer->isCPP(), true, tok->astOperand1(), tok->astOperand2(), mSettings->library, true, true))
|
||||
continue;
|
||||
// ensure that there is a integer variable in expression with unknown value
|
||||
const Token* vartok = findAstNode(tok, [](const Token* child) {
|
||||
const Token* vartok = nullptr;
|
||||
visitAstNodes(tok, [&](const Token* child) {
|
||||
if (Token::Match(child, "%var%|.|[")) {
|
||||
return astIsIntegral(child, false) && !astIsPointer(child) && child->values().empty();
|
||||
if (child->hasKnownIntValue())
|
||||
return ChildrenToVisit::none;
|
||||
if (astIsIntegral(child, false) && !astIsPointer(child) && child->values().empty()) {
|
||||
vartok = child;
|
||||
return ChildrenToVisit::done;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return ChildrenToVisit::op1_and_op2;
|
||||
});
|
||||
if (!vartok)
|
||||
continue;
|
||||
|
|
|
@ -11033,6 +11033,18 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #11894
|
||||
check("struct S {\n"
|
||||
" int *p, n;\n"
|
||||
"};\n"
|
||||
"S* g() {\n"
|
||||
" S* s = static_cast<S*>(calloc(1, sizeof(S)));\n"
|
||||
" s->n = 100;\n"
|
||||
" s->p = static_cast<int*>(malloc(s->n * sizeof(int)));\n"
|
||||
" return s;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #11679
|
||||
check("bool g(int);\n"
|
||||
"void h(int);\n"
|
||||
|
|
Loading…
Reference in New Issue