Conversation
danmar
left a comment
There was a problem hiding this comment.
it looks good to me. just have some nits to simplify the code a little.
apply simplification Co-authored-by: Daniel Marjamäki <daniel.marjamaki@gmail.com>
apply simplification Co-authored-by: Daniel Marjamäki <daniel.marjamaki@gmail.com>
|
If the simplifications were the last changes to make, I think this is ready to merge! Thanks for the review :) |
|
|
||
| checkUninitVar("void g() {\n" | ||
| " int* p = new int;\n" | ||
| " ++p; // FP\n" |
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 button
The change looks safe to me from the false-positive point of view. The new isVariableUsage() branch only returns "not a usage" for a pointer/array that is not dereferenced. The %assign% change in checkScopeForVariable() only adds a check of the right-hand side; the "assume that variable is assigned" path after it is unchanged. CI is green.
Small nit: the // FP here reads as if a false positive is expected, but the test asserts no warning. Maybe drop it, or write // #15005 as the reference? There's also a double blank line before the first new test.
isVariableUsage() currently returns nullptr for the lhs of assignment operators, because unless it's a pointer that gets dereferenced, it is just getting overwritten and its potentially uninitialized value is not read. I extend this idea to compound assignment and increment/decrement operators.
While working on this, I found some issues with CTU analysis.
this test only works because of the false positive "usage" from the increment operator. For example, this test breaks if we use regular assignment because of the current code properly handling "="
this code
misses the ctu error, and only throws
I think that the problem has to do with
the hardcoded pointer=true and alloc=ARRAY assignments tell isVariableUsage to return nullptr if it i isn't dereferenced, which it isn't. If we are going to hardcode these values to be this conservative then this test should fail because it currently only passes due to the FP bug I want to fix. I currently have a workaround where I use vartok->variable() to determine whether something is actually a pointer/array.
Maybe there can be another PR where we rework the ctu/uninitvar connection. Notably since I don't touch the "=" branch of the code the false negative I mentioned above remains unfixed. Let me know if I should apply my vartok workaround to that code in this PR, if it should be another PR, or if its just the wrong idea overall.