[bindings] Fix CVecTempl clone operation behavior.
authorMatt Corallo <git@bluematt.me>
Tue, 20 Oct 2020 17:59:02 +0000 (13:59 -0400)
committerMatt Corallo <git@bluematt.me>
Mon, 23 Nov 2020 16:08:34 +0000 (11:08 -0500)
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.

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

index 840bd7a4446a5b07c59658e66686d734f680de38..1919277902306bfcf98b36b0661189b0538ec921 100644 (file)
@@ -320,7 +320,7 @@ impl<T: Clone> Clone for CVecTempl<T> {
        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)
        }
 }