Correctly handle possibly misaligned pointers in readdir (#615)

This commit is contained in:
Marcin Mielniczuk
2019-11-28 04:11:32 +01:00
committed by Dan Gohman
parent 16b8b3e58d
commit b69758f672
2 changed files with 3 additions and 3 deletions

View File

@@ -1088,12 +1088,12 @@ impl Dirent {
let sys_dirent = raw.as_mut_ptr() as *mut wasi::__wasi_dirent_t;
unsafe {
*sys_dirent = wasi::__wasi_dirent_t {
sys_dirent.write_unaligned(wasi::__wasi_dirent_t {
d_namlen: namlen.try_into()?,
d_ino: self.ino,
d_next: self.cookie,
d_type: self.ftype.to_wasi(),
};
});
}
let sys_name = unsafe { sys_dirent.offset(1) as *mut u8 };