Skip to content

Fix #8260 Improve check: Pointer calculation result not null#8061

Open
francois-berder wants to merge 2 commits intodanmar:mainfrom
francois-berder:pr-8260
Open

Fix #8260 Improve check: Pointer calculation result not null#8061
francois-berder wants to merge 2 commits intodanmar:mainfrom
francois-berder:pr-8260

Conversation

@francois-berder
Copy link
Copy Markdown
Contributor

No description provided.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@pfultz2 pfultz2 left a comment

Choose a reason for hiding this comment

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

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.

ASSERT_EQUALS("[test.cpp:2:15]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. [pointerAdditionResultNotNull]\n", errout_str());

// #8260
check("void f(int *p) {\n"
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.

Is it worth adding a test for the original example from #8260?

Signed-off-by: Francois Berder <fberder@outlook.fr>
@francois-berder
Copy link
Copy Markdown
Contributor Author

@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.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 3, 2026

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