Skip to content

Fix #15077 FP uninitvar for array of std::vector - #8908

Open
chrchr-github wants to merge 9 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_15077
Open

chrchr-github wants to merge 9 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_15077

Conversation

@chrchr-github

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread lib/valueflow.cpp Outdated
Comment thread lib/checkbufferoverrun.cpp Fixed
Comment thread lib/valueflow.cpp
setTokenValue(tok, std::move(value), settings);
} else if (tok->variable() && tok->variable()->isArray() && !tok->variable()->isArgument() &&
tok->variable()->getTypeName() != "std::array") {
!tok->variable()->isStlType("array")) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is an AI review take it with a grain of salt. Please feel free to reject it by clicking on Resolve

isStlType("array") is not exactly equivalent to the old getTypeName() == "std::array". It only checks typeStartToken()->strAt(2), so nested types such as std::array<int,3>::value_type are now treated as std::array too. I compared main and this PR:

void h1() { std::array<int,3>::value_type a[2] = {}; if (a) {} }
void h2() { std::array<int,3>::value_type a[2] = {}; if (a == nullptr) {} }

main: knownConditionTrueFalse on both (correct, it is a plain int[2]).
PR: no knownConditionTrueFalse, but instead a new FP nullPointerRedundantCheck: Either the condition 'a' is redundant or there is possible null pointer dereference on both lines.

The same applies to valueFlowArrayBool() (line 730). It is admittedly an unusual way to write code, and the warnings on lib/, cli/, test/cfg/ and samples/ are identical, so it is minor. But it could be avoided by keeping getTypeName() == "std::array" in the places that only did a rename, or by making Variable::isStlType(const std::string&) reject a type that continues with :: after the template arguments.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@danmar: Do you see what's happening here? First, there is a suggestion, and only after adopting it I'm told it's a bad idea. What a waste of time.

Comment thread lib/checksizeof.cpp

const Variable *var = varTok->variable();
if (var && var->isArray() && var->isArgument() && !var->isReference() && !(var->isStlType() && var->getTypeName() == "std::array"))
if (var && var->isArray() && var->isArgument() && !var->isReference() && !var->isStlType("array"))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is an AI review take it with a grain of salt. Please feel free to reject it by clicking on Resolve

Same isStlType("array") vs getTypeName() == "std::array" difference as in valueflow.cpp. This one causes a false negative:

int g6(std::array<int,3>::value_type a[2]) { return sizeof(a); }

main warns sizeofwithsilentarraypointer, the PR is silent. (The old code here had both isStlType() and getTypeName() == "std::array", so it was exact.)

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.

3 participants