Correctly interpret boolean literals in `execute()` (#4251)
* Correctly interpret boolean literals in `execute()` * Add regeression test case for boolean literals
This commit is contained in:
parent
bd92e7411c
commit
c17e2b9826
|
@ -632,6 +632,8 @@ static ValueFlow::Value executeImpl(const Token* expr, ProgramMemory& pm, const
|
||||||
if (MathLib::isFloat(expr->str()))
|
if (MathLib::isFloat(expr->str()))
|
||||||
return unknown;
|
return unknown;
|
||||||
return ValueFlow::Value{MathLib::toLongNumber(expr->str())};
|
return ValueFlow::Value{MathLib::toLongNumber(expr->str())};
|
||||||
|
} else if (expr->isBoolean()) {
|
||||||
|
return ValueFlow::Value{ expr->str() == "true" };
|
||||||
} else if (Token::Match(expr->tokAt(-2), ". %name% (") && astIsContainer(expr->tokAt(-2)->astOperand1())) {
|
} else if (Token::Match(expr->tokAt(-2), ". %name% (") && astIsContainer(expr->tokAt(-2)->astOperand1())) {
|
||||||
const Token* containerTok = expr->tokAt(-2)->astOperand1();
|
const Token* containerTok = expr->tokAt(-2)->astOperand1();
|
||||||
Library::Container::Yield yield = containerTok->valueType()->container->getYield(expr->strAt(-1));
|
Library::Container::Yield yield = containerTok->valueType()->container->getYield(expr->strAt(-1));
|
||||||
|
|
|
@ -3623,6 +3623,17 @@ private:
|
||||||
" if (a[i]) {}\n"
|
" if (a[i]) {}\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
valueFlowUninit("void f(void) {\n"
|
||||||
|
" char *c;\n"
|
||||||
|
" char x;\n"
|
||||||
|
" while (true) {\n"
|
||||||
|
" c = &x;\n"
|
||||||
|
" break;\n"
|
||||||
|
" }\n"
|
||||||
|
" ++c;\n"
|
||||||
|
"}", "test.c");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitStructMember() { // struct members
|
void uninitStructMember() { // struct members
|
||||||
|
|
Loading…
Reference in New Issue