fix again

This commit is contained in:
Szymon Walter 2018-03-19 00:01:21 +01:00
parent a9d5677c57
commit 43e400ef08
2 changed files with 8 additions and 20 deletions

View file

@ -1,11 +1,4 @@
#[cfg(test)]
use std::mem;
#[cfg(test)]
use std::slice;
#[cfg(not(test))]
use core::mem;
#[cfg(not(test))]
use core::slice;
use error::Error;
@ -52,11 +45,9 @@ impl BlockGroupDescriptor {
return Err(Error::OutOfBounds(end));
}
let ptr = unsafe {
haystack.as_mut_ptr().offset(offset as isize)
as *mut BlockGroupDescriptor
};
let slice = unsafe { slice::from_raw_parts_mut(ptr, count) };
let ptr = haystack.as_mut_ptr().offset(offset as isize)
as *mut BlockGroupDescriptor;
let slice = slice::from_raw_parts_mut(ptr, count);
Ok(slice)
}
}
@ -70,8 +61,9 @@ mod tests {
let mut buffer = vec![0_u8; 4096];
let addr = &buffer[2048] as *const _ as usize;
// magic
let table =
BlockGroupDescriptor::find_descriptor_table(&mut buffer, 0, 0);
let table = unsafe {
BlockGroupDescriptor::find_descriptor_table(&mut buffer, 0, 0)
};
assert!(
table.is_ok(),
"Err({:?})",

View file

@ -1,7 +1,3 @@
#[cfg(test)]
use std::mem;
#[cfg(not(test))]
use core::mem;
use error::Error;
@ -157,7 +153,7 @@ impl Superblock {
return Err(Error::OutOfBounds(end));
}
let superblock: &mut Superblock = unsafe {
let superblock: &mut Superblock = {
let ptr = haystack.as_mut_ptr().offset(offset as isize)
as *mut Superblock;
ptr.as_mut().unwrap()
@ -251,7 +247,7 @@ mod tests {
// magic
buffer[1024 + 56] = EXT2_MAGIC as u8;
buffer[1024 + 57] = (EXT2_MAGIC >> 8) as u8;
let superblock = Superblock::find(&mut buffer, 0);
let superblock = unsafe { Superblock::find(&mut buffer, 0) };
assert!(
superblock.is_ok(),
"Err({:?})",