Skip to content

Commit 1ace961

Browse files
authored
Merge pull request #300 from RalfJung/panic
avoid ptr::write which might panic in debug mode
2 parents 5e06435 + 25edd20 commit 1ace961

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/arm.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,12 @@ pub unsafe extern "aapcs" fn __aeabi_memcpy(dest: *mut u8, src: *const u8, n: us
135135
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
136136
#[cfg_attr(thumb, linkage = "weak")]
137137
pub unsafe extern "aapcs" fn __aeabi_memcpy4(dest: *mut u8, src: *const u8, mut n: usize) {
138-
use core::ptr;
139-
138+
// We are guaranteed 4-alignment, so accessing at u32 is okay.
140139
let mut dest = dest as *mut u32;
141140
let mut src = src as *mut u32;
142141

143142
while n >= 4 {
144-
ptr::write(dest, ptr::read(src));
143+
*dest = *src;
145144
dest = dest.offset(1);
146145
src = src.offset(1);
147146
n -= 4;
@@ -190,15 +189,13 @@ pub unsafe extern "aapcs" fn __aeabi_memset(dest: *mut u8, n: usize, c: i32) {
190189
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
191190
#[cfg_attr(thumb, linkage = "weak")]
192191
pub unsafe extern "aapcs" fn __aeabi_memset4(dest: *mut u8, mut n: usize, c: i32) {
193-
use core::ptr;
194-
195192
let mut dest = dest as *mut u32;
196193

197194
let byte = (c as u32) & 0xff;
198195
let c = (byte << 24) | (byte << 16) | (byte << 8) | byte;
199196

200197
while n >= 4 {
201-
ptr::write(dest, c);
198+
*dest = c;
202199
dest = dest.offset(1);
203200
n -= 4;
204201
}

0 commit comments

Comments
 (0)