Remove unsafe code
This commit is contained in:
1 parent
ee82baa9c8
commit
fab6734275
2 files changed
+6
-11
No files matched your search
@@ -118,6 +118,7 @@ impl Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Entry {
|
pub struct Entry {
|
||||||
type_: Type,
|
type_: Type,
|
||||||
count: u32,
|
count: u32,
|
||||||
|
|||||||
+5
-11
@@ -1,5 +1,4 @@
|
|||||||
use std::io::{self, Read, Seek};
|
use std::io::{self, Read, Seek};
|
||||||
use std::mem;
|
|
||||||
use num_traits::{FromPrimitive, Num};
|
use num_traits::{FromPrimitive, Num};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::string::FromUtf8Error;
|
use std::string::FromUtf8Error;
|
||||||
@@ -343,17 +342,12 @@ impl<R: Read + Seek> Decoder<R> {
|
|||||||
/// Tries to retrieve a tag.
|
/// Tries to retrieve a tag.
|
||||||
/// Return `Ok(None)` if the tag is not present.
|
/// Return `Ok(None)` if the tag is not present.
|
||||||
pub fn find_tag(&mut self, tag: ifd::Tag) -> TiffResult<Option<ifd::Value>> {
|
pub fn find_tag(&mut self, tag: ifd::Tag) -> TiffResult<Option<ifd::Value>> {
|
||||||
let ifd: &Directory = unsafe {
|
let entry = match self.ifd.as_ref().unwrap().get(&tag) {
|
||||||
let ifd = self.ifd.as_ref().unwrap(); // Ok to fail
|
None => return Ok(None),
|
||||||
// Get a immutable borrow of self
|
Some(entry) => entry.clone(),
|
||||||
// This is ok because entry val only changes the stream
|
|
||||||
// but not the directory.
|
|
||||||
mem::transmute_copy(&ifd)
|
|
||||||
};
|
};
|
||||||
match ifd.get(&tag) {
|
|
||||||
None => Ok(None),
|
Ok(Some(try!(entry.val(self))))
|
||||||
Some(entry) => Ok(Some(try!(entry.val(self))))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to retrieve a tag and convert it to the desired type.
|
/// Tries to retrieve a tag and convert it to the desired type.
|
||||||
|
|||||||
Reference in new issue
Block a user