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

Improve safety of the C interface implementation #37

Merged
merged 5 commits into from
Nov 12, 2024
Merged

Conversation

bjorn3
Copy link
Collaborator

@bjorn3 bjorn3 commented Nov 12, 2024

No description provided.

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
bzlib.rs 94.44% 5 Missing ⚠️
Files with missing lines Coverage Δ
bzlib.rs 87.84% <94.44%> (-0.51%) ⬇️

}

if !s.is_null() {
Copy link
Collaborator Author

@bjorn3 bjorn3 Nov 12, 2024

Choose a reason for hiding this comment

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

We are already dereferencing this pointer before this point anyway, so s has to be a non-NULL pointer to not have UB. And if allocation failed, we should return BZ_MEM_ERROR before this. No need to check for NULL again.

}
s.arr1.dealloc(bzfree, strm.opaque);
s.arr2.dealloc(bzfree, strm.opaque);
s.ftab.dealloc(bzfree, strm.opaque);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

dealloc checks if the value exists before deallocating.

bzlib.rs Outdated Show resolved Hide resolved
@bjorn3 bjorn3 merged commit 84e6a56 into main Nov 12, 2024
11 checks passed
@bjorn3 bjorn3 deleted the less_unsafe branch November 12, 2024 14:11
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.

2 participants