Skip to content

Commit cbf805f

Browse files
committed
Avoid ptr->usize->ptr conversion to comply strict provenance
1 parent c926327 commit cbf805f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/userdata/registry.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type StaticFieldCallback = Box<dyn FnOnce(&RawLua) -> Result<()> + 'static>;
3131
#[derive(Clone, Copy)]
3232
enum UserDataTypeId {
3333
Shared(TypeId),
34-
Unique(usize),
34+
Unique(*mut c_void),
3535

3636
#[cfg(all(feature = "userdata-wrappers", not(feature = "send")))]
3737
Rc(TypeId),
@@ -77,7 +77,7 @@ impl<T> UserDataRegistry<T> {
7777

7878
#[inline(always)]
7979
pub(crate) fn new_unique(ud_ptr: *mut c_void) -> Self {
80-
Self::with_type_id(UserDataTypeId::Unique(ud_ptr as usize))
80+
Self::with_type_id(UserDataTypeId::Unique(ud_ptr))
8181
}
8282

8383
#[inline(always)]
@@ -157,7 +157,7 @@ impl<T> UserDataRegistry<T> {
157157
}
158158
#[rustfmt::skip]
159159
UserDataTypeId::Unique(target_ptr)
160-
if get_userdata::<UserDataStorage<T>>(state, self_index) as usize == target_ptr =>
160+
if get_userdata::<UserDataStorage<T>>(state, self_index) as *mut c_void == target_ptr =>
161161
{
162162
let ud = target_ptr as *mut UserDataStorage<T>;
163163
try_self_arg!((*ud).try_borrow_scoped(|ud| {
@@ -285,7 +285,7 @@ impl<T> UserDataRegistry<T> {
285285
}
286286
#[rustfmt::skip]
287287
UserDataTypeId::Unique(target_ptr)
288-
if get_userdata::<UserDataStorage<T>>(state, self_index) as usize == target_ptr =>
288+
if get_userdata::<UserDataStorage<T>>(state, self_index) as *mut c_void == target_ptr =>
289289
{
290290
let ud = target_ptr as *mut UserDataStorage<T>;
291291
try_self_arg!((*ud).try_borrow_scoped_mut(|ud| {

0 commit comments

Comments
 (0)