Skip to content

Commit 430a292

Browse files
committed
Add lint unsafe_sizeof_count_copies
1 parent 68cf94f commit 430a292

File tree

6 files changed

+293
-0
lines changed

6 files changed

+293
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,7 @@ Released 2018-09-13
21232123
[`unreadable_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal
21242124
[`unsafe_derive_deserialize`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_derive_deserialize
21252125
[`unsafe_removed_from_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_removed_from_name
2126+
[`unsafe_sizeof_count_copies`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_sizeof_count_copies
21262127
[`unsafe_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_vector_initialization
21272128
[`unseparated_literal_suffix`]: https://rust-lang.github.io/rust-clippy/master/index.html#unseparated_literal_suffix
21282129
[`unsound_collection_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsound_collection_transmute

clippy_lints/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ mod unnecessary_sort_by;
328328
mod unnecessary_wraps;
329329
mod unnested_or_patterns;
330330
mod unsafe_removed_from_name;
331+
mod unsafe_sizeof_count_copies;
331332
mod unused_io_amount;
332333
mod unused_self;
333334
mod unused_unit;
@@ -896,6 +897,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
896897
&unnecessary_wraps::UNNECESSARY_WRAPS,
897898
&unnested_or_patterns::UNNESTED_OR_PATTERNS,
898899
&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
900+
&unsafe_sizeof_count_copies::UNSAFE_SIZEOF_COUNT_COPIES,
899901
&unused_io_amount::UNUSED_IO_AMOUNT,
900902
&unused_self::UNUSED_SELF,
901903
&unused_unit::UNUSED_UNIT,
@@ -982,6 +984,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
982984
let msrv = parsed_msrv;
983985
store.register_late_pass(move || box manual_strip::ManualStrip::new(msrv.clone()));
984986

987+
store.register_late_pass(|| box unsafe_sizeof_count_copies::UnsafeSizeofCountCopies);
985988
store.register_late_pass(|| box map_clone::MapClone);
986989
store.register_late_pass(|| box map_err_ignore::MapErrIgnore);
987990
store.register_late_pass(|| box shadow::Shadow);
@@ -1593,6 +1596,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15931596
LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY),
15941597
LintId::of(&unnecessary_wraps::UNNECESSARY_WRAPS),
15951598
LintId::of(&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME),
1599+
LintId::of(&unsafe_sizeof_count_copies::UNSAFE_SIZEOF_COUNT_COPIES),
15961600
LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT),
15971601
LintId::of(&unused_unit::UNUSED_UNIT),
15981602
LintId::of(&unwrap::PANICKING_UNWRAP),
@@ -1870,6 +1874,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
18701874
LintId::of(&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD),
18711875
LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS),
18721876
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
1877+
LintId::of(&unsafe_sizeof_count_copies::UNSAFE_SIZEOF_COUNT_COPIES),
18731878
LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT),
18741879
LintId::of(&unwrap::PANICKING_UNWRAP),
18751880
LintId::of(&vec_resize_to_zero::VEC_RESIZE_TO_ZERO),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//! Lint on unsafe memory copying that use the `size_of` of the pointee type instead of a pointee
2+
//! count
3+
4+
use crate::utils::{match_def_path, paths, span_lint_and_help};
5+
use if_chain::if_chain;
6+
use rustc_hir::BinOpKind;
7+
use rustc_hir::{Expr, ExprKind};
8+
use rustc_lint::{LateContext, LateLintPass};
9+
use rustc_middle::ty::{Ty as TyM, TyS};
10+
use rustc_session::{declare_lint_pass, declare_tool_lint};
11+
12+
declare_clippy_lint! {
13+
/// **What it does:** Detects expressions where
14+
/// size_of::<T> is used as the count argument to unsafe
15+
/// memory copying functions like ptr::copy and
16+
/// ptr::copy_nonoverlapping where T is the pointee type
17+
/// of the pointers used
18+
///
19+
/// **Why is this bad?** These functions expect a count
20+
/// of T and not a number of bytes, which can lead to
21+
/// copying the incorrect amount of bytes, which can
22+
/// result in Undefined Behaviour
23+
///
24+
/// **Known problems:** None.
25+
///
26+
/// **Example:**
27+
/// ```rust,no_run
28+
/// # use std::ptr::copy_nonoverlapping;
29+
/// # use std::mem::size_of;
30+
///
31+
/// const SIZE: usize = 128;
32+
/// let x = [2u8; SIZE];
33+
/// let y = [2u8; SIZE];
34+
/// unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * SIZE) };
35+
/// ```
36+
pub UNSAFE_SIZEOF_COUNT_COPIES,
37+
correctness,
38+
"unsafe memory copying using a byte count instead of a count of T"
39+
}
40+
41+
declare_lint_pass!(UnsafeSizeofCountCopies => [UNSAFE_SIZEOF_COUNT_COPIES]);
42+
43+
fn get_size_of_ty(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<TyM<'tcx>> {
44+
match &expr.kind {
45+
ExprKind::Call(ref count_func, _func_args) => {
46+
if_chain! {
47+
if let ExprKind::Path(ref count_func_qpath) = count_func.kind;
48+
if let Some(def_id) = cx.qpath_res(count_func_qpath, count_func.hir_id).opt_def_id();
49+
if match_def_path(cx, def_id, &paths::MEM_SIZE_OF)
50+
|| match_def_path(cx, def_id, &paths::MEM_SIZE_OF_VAL);
51+
then {
52+
cx.typeck_results().node_substs(count_func.hir_id).types().next()
53+
} else {
54+
None
55+
}
56+
}
57+
},
58+
ExprKind::Binary(op, left, right) if BinOpKind::Mul == op.node || BinOpKind::Div == op.node => {
59+
get_size_of_ty(cx, &*left).or_else(|| get_size_of_ty(cx, &*right))
60+
},
61+
_ => None,
62+
}
63+
}
64+
65+
impl<'tcx> LateLintPass<'tcx> for UnsafeSizeofCountCopies {
66+
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
67+
if_chain! {
68+
// Find calls to ptr::copy and copy_nonoverlapping
69+
if let ExprKind::Call(ref func, ref func_args) = expr.kind;
70+
if let ExprKind::Path(ref func_qpath) = func.kind;
71+
if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id();
72+
if match_def_path(cx, def_id, &paths::COPY_NONOVERLAPPING)
73+
|| match_def_path(cx, def_id, &paths::COPY);
74+
75+
// Get the pointee type
76+
let _substs = cx.typeck_results().node_substs(func.hir_id);
77+
if let Some(pointee_ty) = cx.typeck_results().node_substs(func.hir_id).types().next();
78+
79+
// Find a size_of call in the count parameter expression and
80+
// check that it's the same type
81+
if let [_src, _dest, count] = &**func_args;
82+
if let Some(ty_used_for_size_of) = get_size_of_ty(cx, count);
83+
if TyS::same_type(pointee_ty, ty_used_for_size_of);
84+
then {
85+
span_lint_and_help(
86+
cx,
87+
UNSAFE_SIZEOF_COUNT_COPIES,
88+
expr.span,
89+
"unsafe memory copying using a byte count (Multiplied by size_of::<T>) \
90+
instead of a count of T",
91+
None,
92+
"use a count of elements instead of a count of bytes for the count parameter, \
93+
it already gets multiplied by the size of the pointed to type"
94+
);
95+
}
96+
};
97+
}
98+
}

clippy_lints/src/utils/paths.rs

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub const CLONE_TRAIT: [&str; 3] = ["core", "clone", "Clone"];
2020
pub const CLONE_TRAIT_METHOD: [&str; 4] = ["core", "clone", "Clone", "clone"];
2121
pub const CMP_MAX: [&str; 3] = ["core", "cmp", "max"];
2222
pub const CMP_MIN: [&str; 3] = ["core", "cmp", "min"];
23+
pub const COPY: [&str; 3] = ["core", "intrinsics", "copy_nonoverlapping"];
24+
pub const COPY_NONOVERLAPPING: [&str; 3] = ["core", "intrinsics", "copy"];
2325
pub const COW: [&str; 3] = ["alloc", "borrow", "Cow"];
2426
pub const CSTRING_AS_C_STR: [&str; 5] = ["std", "ffi", "c_str", "CString", "as_c_str"];
2527
pub const DEFAULT_TRAIT: [&str; 3] = ["core", "default", "Default"];
@@ -70,6 +72,8 @@ pub const MEM_MANUALLY_DROP: [&str; 4] = ["core", "mem", "manually_drop", "Manua
7072
pub const MEM_MAYBEUNINIT: [&str; 4] = ["core", "mem", "maybe_uninit", "MaybeUninit"];
7173
pub const MEM_MAYBEUNINIT_UNINIT: [&str; 5] = ["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"];
7274
pub const MEM_REPLACE: [&str; 3] = ["core", "mem", "replace"];
75+
pub const MEM_SIZE_OF: [&str; 3] = ["core", "mem", "size_of"];
76+
pub const MEM_SIZE_OF_VAL: [&str; 3] = ["core", "mem", "size_of_val"];
7377
pub const MUTEX_GUARD: [&str; 4] = ["std", "sync", "mutex", "MutexGuard"];
7478
pub const OPEN_OPTIONS: [&str; 3] = ["std", "fs", "OpenOptions"];
7579
pub const OPS_MODULE: [&str; 2] = ["core", "ops"];
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#![warn(clippy::unsafe_sizeof_count_copies)]
2+
3+
use std::mem::{size_of, size_of_val};
4+
use std::ptr::{copy, copy_nonoverlapping};
5+
6+
fn main() {
7+
const SIZE: usize = 128;
8+
const HALF_SIZE: usize = SIZE / 2;
9+
const DOUBLE_SIZE: usize = SIZE * 2;
10+
let mut x = [2u8; SIZE];
11+
let mut y = [2u8; SIZE];
12+
13+
// Count is size_of (Should trigger the lint)
14+
unsafe { copy_nonoverlapping::<u8>(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>()) };
15+
unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) };
16+
17+
unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>()) };
18+
unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) };
19+
20+
// Count expression involving multiplication of size_of (Should trigger the lint)
21+
unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * SIZE) };
22+
unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0]) * SIZE) };
23+
24+
unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * SIZE) };
25+
unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0]) * SIZE) };
26+
27+
// Count expression involving nested multiplications of size_of (Should trigger the lint)
28+
unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * HALF_SIZE * 2) };
29+
unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) };
30+
31+
unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * SIZE * HALF_SIZE) };
32+
unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0]) * HALF_SIZE * 2) };
33+
34+
// Count expression involving divisions of size_of (Should trigger the lint)
35+
unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * DOUBLE_SIZE / 2) };
36+
unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / 2 * size_of_val(&x[0])) };
37+
38+
unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::<u8>() / 2) };
39+
unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0]) * DOUBLE_SIZE / 2) };
40+
41+
// No size_of calls (Should not trigger the lint)
42+
unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), SIZE) };
43+
unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), SIZE) };
44+
45+
unsafe { copy(x.as_ptr(), y.as_mut_ptr(), SIZE) };
46+
unsafe { copy(x.as_ptr(), y.as_mut_ptr(), SIZE) };
47+
48+
// Different types for pointee and size_of (Should not trigger the lint)
49+
unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::<u16>() / 2 * SIZE) };
50+
unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&0u16) / 2 * SIZE) };
51+
52+
unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::<u16>() / 2 * SIZE) };
53+
unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&0u16) / 2 * SIZE) };
54+
}
+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
2+
--> $DIR/unsafe_sizeof_count_copies.rs:14:14
3+
|
4+
LL | unsafe { copy_nonoverlapping::<u8>(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>()) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::unsafe-sizeof-count-copies` implied by `-D warnings`
8+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
9+
10+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
11+
--> $DIR/unsafe_sizeof_count_copies.rs:15:14
12+
|
13+
LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) };
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
17+
18+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
19+
--> $DIR/unsafe_sizeof_count_copies.rs:17:14
20+
|
21+
LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>()) };
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
|
24+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
25+
26+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
27+
--> $DIR/unsafe_sizeof_count_copies.rs:18:14
28+
|
29+
LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) };
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
33+
34+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
35+
--> $DIR/unsafe_sizeof_count_copies.rs:21:14
36+
|
37+
LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * SIZE) };
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39+
|
40+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
41+
42+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
43+
--> $DIR/unsafe_sizeof_count_copies.rs:22:14
44+
|
45+
LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0]) * SIZE) };
46+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47+
|
48+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
49+
50+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
51+
--> $DIR/unsafe_sizeof_count_copies.rs:24:14
52+
|
53+
LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * SIZE) };
54+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55+
|
56+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
57+
58+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
59+
--> $DIR/unsafe_sizeof_count_copies.rs:25:14
60+
|
61+
LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0]) * SIZE) };
62+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
63+
|
64+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
65+
66+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
67+
--> $DIR/unsafe_sizeof_count_copies.rs:28:14
68+
|
69+
LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * HALF_SIZE * 2) };
70+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71+
|
72+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
73+
74+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
75+
--> $DIR/unsafe_sizeof_count_copies.rs:29:14
76+
|
77+
LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) };
78+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79+
|
80+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
81+
82+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
83+
--> $DIR/unsafe_sizeof_count_copies.rs:31:14
84+
|
85+
LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * SIZE * HALF_SIZE) };
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
|
88+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
89+
90+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
91+
--> $DIR/unsafe_sizeof_count_copies.rs:32:14
92+
|
93+
LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0]) * HALF_SIZE * 2) };
94+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
95+
|
96+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
97+
98+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
99+
--> $DIR/unsafe_sizeof_count_copies.rs:35:14
100+
|
101+
LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * DOUBLE_SIZE / 2) };
102+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103+
|
104+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
105+
106+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
107+
--> $DIR/unsafe_sizeof_count_copies.rs:36:14
108+
|
109+
LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / 2 * size_of_val(&x[0])) };
110+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111+
|
112+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
113+
114+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
115+
--> $DIR/unsafe_sizeof_count_copies.rs:38:14
116+
|
117+
LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::<u8>() / 2) };
118+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
119+
|
120+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
121+
122+
error: unsafe memory copying using a byte count (Multiplied by size_of::<T>) instead of a count of T
123+
--> $DIR/unsafe_sizeof_count_copies.rs:39:14
124+
|
125+
LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0]) * DOUBLE_SIZE / 2) };
126+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127+
|
128+
= help: use a count of elements instead of a count of bytes for the count parameter, it already gets multiplied by the size of the pointed to type
129+
130+
error: aborting due to 16 previous errors
131+

0 commit comments

Comments
 (0)