Skip to content

assert flawed known value usage #7394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6779,6 +6779,7 @@ static void valueFlowDynamicBufferSize(const TokenList& tokenlist, const SymbolD
case Library::AllocFunc::BufferSize::strdup:
if (arg1 && arg1->hasKnownValue()) {
const ValueFlow::Value& value = arg1->values().back();
assert(value.isKnown());
if (value.isTokValue() && value.tokvalue->tokType() == Token::eString)
sizeValue = Token::getStrLength(value.tokvalue) + 1; // Add one for the null terminator
}
Expand Down Expand Up @@ -7037,7 +7038,10 @@ const ValueFlow::Value *ValueFlow::valueFlowConstantFoldAST(Token *expr, const S
valueFlowConstantFoldAST(expr->astOperand2(), settings);
valueFlowSetConstantValue(expr, settings);
}
return expr && expr->hasKnownValue() ? &expr->values().front() : nullptr;
const auto* v = expr && expr->hasKnownValue() ? &expr->values().front() : nullptr;
if (v)
assert(v->isKnown());
return v;
}

struct ValueFlowState {
Expand Down
1 change: 1 addition & 0 deletions lib/vf_settokenvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ namespace ValueFlow
// is condition always true/false?
if (parent->astOperand1()->hasKnownValue()) {
const Value &condvalue = parent->astOperand1()->values().front();
assert(condvalue.isKnown());
Comment on lines 392 to +395
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails in at least TestLeakAutoVar::assign26. It has two values - the first is INT and Possible, and the other is BUFFER_SIZE and Known.

const bool cond(condvalue.isTokValue() || (condvalue.isIntValue() && condvalue.intvalue != 0));
if (cond && !tok->astOperand1()) { // true condition, no second operator
setTokenValue(parent, condvalue, settings);
Expand Down