Uh oh!
There was an error while loading. Please reload this page.
Fix #8260 Improve check: Pointer calculation result not null - #8061
Fix #8260 Improve check: Pointer calculation result not null#8061francois-berder wants to merge 9 commits into
Conversation
pfultz2
left a comment
There was a problem hiding this comment.
This should be done in valueflow. If there is a plus with a non zero value on a pointer, it should be set to !0. This can probably be done in the valueFlowImpossibleValues pass.
Uh oh!
There was an error while loading. Please reload this page.
francois-berder
commented
Apr 3, 2026
@pfultz2 I finally had time to fix my PR. I rebased my PR on top of main branch, implemented your suggestion and added more test cases. |
danmar
commented
Apr 25, 2026
could you try to execute the test-my-pr.py script. I updated test-my-pr.py today so make sure you syncronize and rebase.. |
danmar
commented
Apr 25, 2026
I got some review comments by AI. Please check. Feel free to ignore stuff you disagree with: 1. Potential null pointer dereference — tok->astParent() in the boolean branch} else if (astIsPointer(tok) && isUsedAsBool(tok, *mSettings) && !tok->astParent()->isComparisonOp()) { tok->astParent() is not guarded. isUsedAsBool may return true in some contexts where the parent is null, so calling } else if (astIsPointer(tok) && isUsedAsBool(tok, *mSettings) && 2. Performance: missing early-exit filter in checkPointerAdditionResultNotNullThe old code had if (!tok->isComparisonOp() || !tok->astOperand1() || !tok->astOperand2()) continue; as an early filter. The new if (!tok->isComparisonOp() && !(astIsPointer(tok) && isUsedAsBool(tok, *mSettings))) 3. Misleading error message for implicit boolean useThe message "Comparison is wrong. Result of 'q' can't be 0..." says "Comparison is wrong" but for if (q) there is no comparison — 4. Missing test cases
|
francois-berder
commented
Apr 25, 2026
I confirm I was able to run test-my-pr.py script. Thank you for fixing this. |
aaa058f to
5c247e7Compare| return Token::simpleMatch(top->astOperand1(), "if") && top->astOperand1()->isConstexpr(); | ||
| } | ||
| static const Token* isPointerArithmeticAdd(const Token* tok) |
There was a problem hiding this comment.
why not return a bool from this function?
francois-berder
commented
Jun 3, 2026
I ran tools/test-my-pr.py but it seems I did it on old code so I have to run it again. |
…t not null Signed-off-by: Francois Berder <fberder@outlook.fr>
…culation result not null
…ter calculation result not null
…k: Pointer calculation result not null
…ve check: Pointer calculation result not null
francois-berder
commented
Jun 4, 2026
I ran tools/test-my-pr with 300 packages (I cannot download lots of packages because I am on a 4G connection and I do not want to run out of data). There is no diff with main. |
francois-berder
commented
Jun 4, 2026
I also ran it on 300 packages without the last commit with no diff with main: |
Uh oh!
There was an error while loading. Please reload this page.
…Improve check: Pointer calculation result not null
…rce#8260 Improve check: Pointer calculation result not null
danmar
left a comment
There was a problem hiding this comment.
just a small nit. almost done!
Uh oh!
There was an error while loading. Please reload this page.
…opensource#8260 Improve check: Pointer calculation result not null
| " int *q = ptr + 1;\n" | ||
| " if (q != 0);\n" | ||
| "}"); | ||
| ASSERT_EQUALS("[test.cpp:3:9]: (warning) Comparison is wrong. Result of 'q' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. [pointerAdditionResultNotNull]\n", errout_str()); |
There was a problem hiding this comment.
we should say where the overflow would happen. it's not on line 3. maybe the calculation is 100 lines above the condition and the developer wonders why we warn..



No description provided.