Skip to content

Fix #14369: Move boolean literal evaluation to valueFlowSetConstantValue#8468

Open
francois-berder wants to merge 1 commit intodanmar:mainfrom
francois-berder:pr-14369
Open

Fix #14369: Move boolean literal evaluation to valueFlowSetConstantValue#8468
francois-berder wants to merge 1 commit intodanmar:mainfrom
francois-berder:pr-14369

Conversation

@francois-berder
Copy link
Copy Markdown
Contributor

Previously, boolean literals were processed in a separate loop after valueFlowSetConstantValue. This triggered nullPointer FP with code such as:

int f() {
const int* p = true ? new int() : nullptr;
return *p; // nullPointer FP
}

Because the condition token had no known value, both branches of the ternary operator were treated as possible, leaking a spurious null value.

Previously, boolean literals were processed in a separate loop after
valueFlowSetConstantValue. This triggered nullPointer FP with code such as:

int f() {
    const int* p = true ? new int() : nullptr;
    return *p; // nullPointer FP
}

Because the condition token had no known value, both branches of the ternary
operator were treated as possible, leaking a spurious null value.

Signed-off-by: Francois Berder <fberder@outlook.fr>
Comment thread lib/vf_common.cpp
if (!tok->isTemplateArg())
value.setKnown();
setTokenValue(tok, std::move(value), settings);
} else if ((tok->isCpp() || settings.standards.c >= Standards::C23) && (tok->isName() && !tok->varId() && Token::Match(tok, "%bool%"))) {
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants