Fix #15077 FP uninitvar for array of std::vector - #8908
chrchr-github wants to merge 9 commits into
Conversation
| 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")) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
|
|
||
| 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")) |
There was a problem hiding this comment.
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.)
No description provided.