You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by uw...@apache.org on 2018/10/21 18:27:53 UTC
[arrow] branch master updated: ARROW-3573: [Rust] with_bitset does
not set valid bits correctly
This is an automated email from the ASF dual-hosted git repository.
uwe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new d656dc3 ARROW-3573: [Rust] with_bitset does not set valid bits correctly
d656dc3 is described below
commit d656dc3fc90b0f1c34b2f44f2c62598da82a24dd
Author: Paddy Horan <pa...@hotmail.com>
AuthorDate: Sun Oct 21 20:27:40 2018 +0200
ARROW-3573: [Rust] with_bitset does not set valid bits correctly
The boundary check is off a little, `MutableBuffer::new(64).with_bitset(64, false);` will fail. This issue only happens if the arguments to `new` and `with_bitset` are the same and a multiple of 64.
`write_bytes` is currently writing 1 instead of 255 to set all the bits when `val` is `true`
cc @kszucs @crepererum @sunchao @andygrove
Author: Paddy Horan <pa...@hotmail.com>
Closes #2803 from paddyhoran/ARROW-3573 and squashes the following commits:
bfd70b89 <Paddy Horan> Updated boundary check and bits set on `true`
---
rust/src/buffer.rs | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/rust/src/buffer.rs b/rust/src/buffer.rs
index 85133d9..005a051 100644
--- a/rust/src/buffer.rs
+++ b/rust/src/buffer.rs
@@ -167,8 +167,8 @@ impl MutableBuffer {
/// the buffer directly (e.g., modifying the buffer by holding a mutable reference
/// from `data_mut()`).
pub fn with_bitset(mut self, end: usize, val: bool) -> Self {
- assert!(end < self.capacity);
- let v = if val { 1 } else { 0 };
+ assert!(end <= self.capacity);
+ let v = if val { 255 } else { 0 };
unsafe {
::std::ptr::write_bytes(self.data, v, end);
self.len = end;
@@ -286,6 +286,7 @@ unsafe impl Send for MutableBuffer {}
mod tests {
use std::ptr::null_mut;
use std::thread;
+ use util::bit_util;
use super::*;
@@ -369,6 +370,17 @@ mod tests {
}
#[test]
+ fn test_with_bitset() {
+ let mut_buf = MutableBuffer::new(64).with_bitset(64, false);
+ let buf = mut_buf.freeze();
+ assert_eq!(0, bit_util::count_set_bits(buf.data()));
+
+ let mut_buf = MutableBuffer::new(64).with_bitset(64, true);
+ let buf = mut_buf.freeze();
+ assert_eq!(512, bit_util::count_set_bits(buf.data()));
+ }
+
+ #[test]
fn test_mutable_new() {
let buf = MutableBuffer::new(63);
assert_eq!(64, buf.capacity());