]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Make `Str`'s `clone` always clone the underlying bytes
authorMatt Corallo <git@bluematt.me>
Mon, 18 Apr 2022 02:56:05 +0000 (02:56 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 18 Apr 2022 02:56:05 +0000 (02:56 +0000)
Its incredibly unexpected that you can clone a higher-level object
(eg an Event with a ClosureReason that contains an `Str`) and have
a pointer back to the original object. To avoid this, `clone` needs
to actually `clone`.

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

index 1e88f0521e53c8ce56372278b3dcb17d3e4db3e5..12c70888b20585ef73b9872dbbb892251af09795 100644 (file)
@@ -569,7 +569,7 @@ impl Into<Str> for String {
 }
 impl Clone for Str {
        fn clone(&self) -> Self {
-               self.into_str().clone().into()
+               String::from(self.into_str()).into()
        }
 }