Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use dangling NonNull as sentinel #3289

Merged
merged 2 commits into from Dec 8, 2022

Conversation

tustvold
Copy link
Contributor

@tustvold tustvold commented Dec 7, 2022

Which issue does this PR close?

Closes #.

Rationale for this change

Aside from a method called null_pointer returning a NonNull being slightly oxymoronic, using the returned value as a sentinel could in extremely unlikely situations lead to a false positive. This would only ever result in leaking memory, but we might as well clean it up.

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Dec 7, 2022
unsafe fn null_pointer() -> NonNull<u8> {
NonNull::new_unchecked(ALIGNMENT as *mut u8)
fn dangling() -> NonNull<u8> {
// SAFETY: ALIGNMENT is a non-zero usize which is then casted
Copy link
Contributor Author

Choose a reason for hiding this comment

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

#[inline]
unsafe fn null_pointer() -> NonNull<u8> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NonNull::new_unchecked(ALIGNMENT as *mut u8)
fn dangling() -> NonNull<u8> {
// SAFETY: ALIGNMENT is a non-zero usize which is then casted
// to a *mut T. Therefore, `ptr` is not null and the conditions for
Copy link
Member

Choose a reason for hiding this comment

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

nit: there is no ptr so might be confused for some readers.

@tustvold tustvold merged commit 2db98ee into apache:master Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants