Skip to content

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

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

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

Conversation

@francois-berder
Copy link
Contributor

No description provided.

@sonarqubecloud
Copy link

Copy link
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
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?

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