fix unsafe keywords

This commit is contained in:
Szymon Walter 2018-03-19 19:36:30 +01:00
parent 959572eca1
commit fb1b5bdef5
3 changed files with 15 additions and 12 deletions

View file

@ -29,7 +29,7 @@ where
Error: From<B::Error>,
{
pub fn new(buffer: B) -> Result<Ext2<B>, Error> {
let superblock = Struct::from(Superblock::find(&buffer)?);
let superblock = unsafe { Struct::from(Superblock::find(&buffer)?) };
let block_size = superblock.inner.block_size();
let block_groups_offset =
(superblock.inner.first_data_block as usize + 1) * block_size;
@ -38,11 +38,13 @@ where
.block_group_count()
.map(|count| count as usize)
.map_err(|(a, b)| Error::BadBlockGroupCount(a, b))?;
let block_groups = BlockGroupDescriptor::find_descriptor_table(
&buffer,
block_groups_offset,
block_groups_count,
)?;
let block_groups = unsafe {
BlockGroupDescriptor::find_descriptor_table(
&buffer,
block_groups_offset,
block_groups_count,
)?
};
let block_groups = Struct::from(block_groups);
Ok(Ext2 {
buffer,

View file

@ -72,7 +72,7 @@ impl BlockGroupDescriptor {
let mut vec = Vec::with_capacity(count);
for i in 0..count {
let offset = offset + i * mem::size_of::<BlockGroupDescriptor>();
vec.push(unsafe {
vec.push({
BlockGroupDescriptor::find_descriptor(haystack, offset)?.0
});
}
@ -88,8 +88,9 @@ mod tests {
#[test]
fn find() {
let buffer = vec![0_u8; 4096];
let table =
BlockGroupDescriptor::find_descriptor_table(&buffer, 2048, 8);
let table = unsafe {
BlockGroupDescriptor::find_descriptor_table(&buffer, 2048, 8)
};
assert!(
table.is_ok(),
"Err({:?})",

View file

@ -157,7 +157,7 @@ impl Superblock {
return Err(Error::OutOfBounds(end));
}
let superblock = unsafe {
let superblock = {
haystack
.slice_unchecked(offset..end)
.dynamic_cast::<Superblock>()
@ -250,7 +250,7 @@ mod tests {
// magic
buffer[1024 + 56] = EXT2_MAGIC as u8;
buffer[1024 + 57] = (EXT2_MAGIC >> 8) as u8;
let superblock = Superblock::find(&buffer);
let superblock = unsafe { Superblock::find(&buffer) };
assert!(
superblock.is_ok(),
"Err({:?})",
@ -265,7 +265,7 @@ mod tests {
use std::fs::File;
let file = RefCell::new(File::open("ext2.bin").unwrap());
let superblock = Superblock::find(&file);
let superblock = unsafe { Superblock::find(&file) };
assert!(
superblock.is_ok(),
"Err({:?})",