Fixed #9914 (False positive: knownArgument for 'x && false')

This commit is contained in:
Daniel Marjamäki 2020-09-25 20:27:16 +02:00
parent 82047ea282
commit 5856fef83b
2 changed files with 17 additions and 0 deletions

View File

@ -3144,6 +3144,12 @@ void CheckOther::checkKnownArgument()
}
if (Token::simpleMatch(child->previous(), "sizeof ("))
return ChildrenToVisit::none;
if (Token::simpleMatch(child, "*") && (Token::simpleMatch(child->astOperand1(), "0") || Token::simpleMatch(child->astOperand2(), "0")))
return ChildrenToVisit::none;
if (Token::simpleMatch(child, "&&") && (Token::simpleMatch(child->astOperand1(), "false") || Token::simpleMatch(child->astOperand2(), "false")))
return ChildrenToVisit::none;
if (Token::simpleMatch(child, "||") && (Token::simpleMatch(child->astOperand1(), "true") || Token::simpleMatch(child->astOperand2(), "true")))
return ChildrenToVisit::none;
return ChildrenToVisit::op1_and_op2;
});
if (varexpr.empty())

View File

@ -8900,6 +8900,17 @@ private:
" dostuff(self->maxsize * sizeof(intptr_t));\n"
"}");
ASSERT_EQUALS("", errout.str());
// #9914 - zeroed expression
check("void f(int x) {\n"
" dostuff(x && false);\n"
" dostuff(false && x);\n"
" dostuff(x || true);\n"
" dostuff(true || x);\n"
" dostuff(x * 0);\n"
" dostuff(0 * x);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void checkComparePointers() {