Skip to content

Commit 9edb453

Browse files
authored
Use ptr.write() instead of directly storing to a ptr for Address.store() (#720)
Storing values using `*ptr = value;` results in `Drop` being called on the old value. This could lead to unexpected behaviours.
1 parent 97fa666 commit 9edb453

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/util/address.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ impl Address {
237237
/// This could throw a segment fault if the address is invalid
238238
#[inline(always)]
239239
pub unsafe fn store<T>(self, value: T) {
240-
*(self.0 as *mut T) = value;
240+
// We use a ptr.write() operation as directly setting the pointer would drop the old value
241+
// which may result in unexpected behaviour
242+
(self.0 as *mut T).write(value);
241243
}
242244

243245
/// atomic operation: load

0 commit comments

Comments
 (0)