From: Matt Corallo Date: Tue, 20 Oct 2020 17:59:02 +0000 (-0400) Subject: [bindings] Fix CVecTempl clone operation behavior. X-Git-Tag: v0.0.12~4^2~7 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=rust-lightning;a=commitdiff_plain;h=faa8ec5c21e685942e5bcafbe74c1f1ce7d54747 [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. --- diff --git a/lightning-c-bindings/src/c_types/mod.rs b/lightning-c-bindings/src/c_types/mod.rs index 840bd7a4..19192779 100644 --- a/lightning-c-bindings/src/c_types/mod.rs +++ b/lightning-c-bindings/src/c_types/mod.rs @@ -320,7 +320,7 @@ impl Clone for CVecTempl { fn clone(&self) -> Self { let mut res = Vec::new(); if self.datalen == 0 { return Self::from(res); } - res.clone_from_slice(unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) }); + res.extend_from_slice(unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) }); Self::from(res) } }