10278: ValueFlow: Wrong known value, sign conversion (#3260)

This commit is contained in:
Paul Fultz II 2021-05-18 00:28:45 -05:00 committed by GitHub
parent 84f8b7b50a
commit 4b11bb4ad3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -1461,7 +1461,7 @@ static std::vector<MathLib::bigint> minUnsignedValue(const Token* tok, int depth
return result;
if (tok->hasKnownIntValue()) {
result = {tok->values().front().intvalue};
} else if (tok->isConstOp() && tok->astOperand1() && tok->astOperand2()) {
} else if (tok->str() != "-" && tok->isConstOp() && tok->astOperand1() && tok->astOperand2()) {
std::vector<MathLib::bigint> op1 = minUnsignedValue(tok->astOperand1(), depth - 1);
std::vector<MathLib::bigint> op2 = minUnsignedValue(tok->astOperand2(), depth - 1);
if (!op1.empty() && !op2.empty()) {

View File

@ -3620,6 +3620,12 @@ private:
" g(name);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'name.empty()' is always true\n", errout.str());
// #10278
check("void foo(unsigned int x) {\n"
" if ((100 - x) > 0) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void alwaysTrueInfer() {