Skip to content

Commit

Permalink
fix bug in setting a data list to a null list
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Oct 15, 2024
1 parent 9bf527e commit 04d2dd6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion capnp/src/private/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,10 @@ mod wire_helpers {
// in the canonicalize=true case.
let whole_byte_size =
u64::from(value.element_count) * u64::from(value.step) / BITS_PER_BYTE as u64;
ptr::copy_nonoverlapping(value.ptr, ptr, whole_byte_size as usize);
if whole_byte_size > 0 {
ptr::copy_nonoverlapping(value.ptr, ptr, whole_byte_size as usize);
}

let leftover_bits =
u64::from(value.element_count) * u64::from(value.step) % BITS_PER_BYTE as u64;
if leftover_bits > 0 {
Expand Down
15 changes: 15 additions & 0 deletions capnpc/test/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,21 @@ mod tests {
}
}

/// https://github.com/capnproto/capnproto-rust/issues/525
#[test]
fn set_data_list_null() {
use crate::test_capnp::test_all_types;

let mut message = message::Builder::new_default();
let root: test_all_types::Builder<'_> = message.init_root();

let mut message2 = message::Builder::new_default();
let mut root2: test_all_types::Builder<'_> = message2.init_root();
root2
.set_data_list(root.into_reader().get_data_list().unwrap())
.unwrap();
}

#[test]
fn double_far_pointer() {
let segment0: &[capnp::Word] = &[
Expand Down

0 comments on commit 04d2dd6

Please sign in to comment.