From ae1315388dc8b37b1a045bf38ddc259909a88922 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 22 Sep 2022 12:39:37 +0100 Subject: [PATCH] Fix subtle UB Pointers derived from `&mut` references must still uphold the uniqueness guarantee. Therefore we should be using a shared reference when duplicating `HSTRING`s. --- crates/libs/windows/src/core/strings/hstring.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/libs/windows/src/core/strings/hstring.rs b/crates/libs/windows/src/core/strings/hstring.rs index 4103ae54a9..cc9fee8c52 100644 --- a/crates/libs/windows/src/core/strings/hstring.rs +++ b/crates/libs/windows/src/core/strings/hstring.rs @@ -408,11 +408,11 @@ impl Header { header } - fn duplicate(&mut self) -> *mut Header { + fn duplicate(&self) -> *mut Header { if self.flags & REFERENCE_FLAG == 0 { // If this is not a "fast pass" string then simply increment the reference count. self.count.add_ref(); - self + self as *const Header as *mut Header } else { // Otherwise, allocate a new string and copy the value into the new string. let copy = Header::alloc(self.len);