Skip to content

Commit ced7993

Browse files
committed
Use pointer casting instead of *::from_raw_parts()
1 parent 0a351c7 commit ced7993

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

elliptic-curve/src/point/non_identity.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,8 @@ where
153153

154154
#[allow(unsafe_code)]
155155
// SAFETY: `NonIdentity` is `repr(transparent)`.
156-
let points: &[P] =
157-
unsafe { core::slice::from_raw_parts(points.as_ptr().cast(), points.len()) };
158-
let mut affine_points = <P as BatchNormalize<_>>::batch_normalize(points);
156+
let points: &[P] = unsafe { &*(points as *const [NonIdentity<P>] as *const [P]) };
157+
let affine_points = <P as BatchNormalize<_>>::batch_normalize(points);
159158

160159
// Ensure casting is safe.
161160
// This always succeeds because `NonIdentity` is `repr(transparent)`.
@@ -168,17 +167,17 @@ where
168167
align_of::<NonIdentity<P::AffineRepr>>()
169168
);
170169

171-
// `Vec::into_raw_parts()` is not stable yet.
172-
let ptr = affine_points.as_mut_ptr();
173-
let length = affine_points.len();
174-
let capacity = affine_points.capacity();
175-
core::mem::forget(affine_points);
176-
177170
#[allow(unsafe_code)]
178171
// SAFETY: `NonIdentity` is `repr(transparent)`.
179-
unsafe {
180-
Vec::from_raw_parts(ptr.cast(), length, capacity)
181-
}
172+
let result: Vec<NonIdentity<P::AffineRepr>> = unsafe {
173+
affine_points
174+
.as_ptr()
175+
.cast::<Vec<NonIdentity<P::AffineRepr>>>()
176+
.read()
177+
};
178+
core::mem::forget(affine_points);
179+
180+
result
182181
}
183182
}
184183

0 commit comments

Comments
 (0)