-
Notifications
You must be signed in to change notification settings - Fork 839
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
Remove undefined behavior in value
method of boolean and primitive arrays
#644
Conversation
@@ -100,7 +100,7 @@ impl BooleanArray { | |||
/// | |||
/// Note this doesn't do any bound checking, for performance reason. | |||
pub fn value(&self, i: usize) -> bool { | |||
debug_assert!(i < self.len()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UB 1
#[inline] | ||
pub fn value(&self, i: usize) -> T::Native { | ||
debug_assert!(i < self.len()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UB 2
pub fn value(&self, i: usize) -> &str { | ||
assert!(i < self.data.len(), "StringArray out of bounds access"); | ||
//Soundness: length checked above, offset buffer length is 1 larger than logical array length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleanup
let comparison = (0..$left.len()).map(|i| $op($left.value(i), $right.value(i))); | ||
// Safety: | ||
// `i < $left.len()` and $left.len() == $right.len() | ||
let comparison = (0..$left.len()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid perf. penalty by using unsafe version here
@@ -121,8 +124,10 @@ macro_rules! compare_op_primitive { | |||
macro_rules! compare_op_scalar { | |||
($left: expr, $right:expr, $op:expr) => {{ | |||
let null_bit_buffer = $left.data().null_buffer().cloned(); | |||
|
|||
let comparison = (0..$left.len()).map(|i| $op($left.value(i), $right)); | |||
// Safety: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid perf. penalty by using unsafe version here
value
methodvalue
method of boolean and primitive arrays
Codecov Report
@@ Coverage Diff @@
## master #644 +/- ##
==========================================
+ Coverage 82.48% 82.51% +0.02%
==========================================
Files 167 168 +1
Lines 46450 47227 +777
==========================================
+ Hits 38315 38968 +653
- Misses 8135 8259 +124
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @Dandandan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a nice cleanup to me. @jorgecarleitao would you like to review this PR as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap, good improvements. Thanks!
…arrays (#644) * Remove UB in `value` * Add safety note
…arrays (#644) (#668) * Remove UB in `value` * Add safety note Co-authored-by: Daniël Heres <[email protected]>
Which issue does this PR close?
Closes #645
Rationale for this change
The value methods only had
debug_assert!
in them, which made that the check is removed in release mode.What changes are included in this PR?
Are there any user-facing changes?