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:
Tau 2022-07-08 10:39:29 +00:00 committed by GitHub
parent bd92e7411c
commit c17e2b9826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -632,6 +632,8 @@ static ValueFlow::Value executeImpl(const Token* expr, ProgramMemory& pm, const
if (MathLib::isFloat(expr->str()))
return unknown;
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())) {
const Token* containerTok = expr->tokAt(-2)->astOperand1();
Library::Container::Yield yield = containerTok->valueType()->container->getYield(expr->strAt(-1));

View File

@ -3623,6 +3623,17 @@ private:
" if (a[i]) {}\n"
"}\n");
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