Skip to content

Commit faa8ec5

Browse files
committed
[bindings] Fix CVecTempl clone operation behavior.
CVecTempl previously called Vec.clone_from_slice() on a newly-allocated Vec, which immediately panics as [T].clone_from_slice() requires that the Vec/target slice already has the same length as the source slice. This should have been Vec.extend_from_slice() which exhibits the correct behavior.
1 parent 336cb08 commit faa8ec5

File tree

1 file changed

+1
-1
lines changed
  • lightning-c-bindings/src/c_types

1 file changed

+1
-1
lines changed

lightning-c-bindings/src/c_types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl<T: Clone> Clone for CVecTempl<T> {
320320
fn clone(&self) -> Self {
321321
let mut res = Vec::new();
322322
if self.datalen == 0 { return Self::from(res); }
323-
res.clone_from_slice(unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) });
323+
res.extend_from_slice(unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) });
324324
Self::from(res)
325325
}
326326
}

0 commit comments

Comments
 (0)