From fab6734275427ca339e40a0403ed355d34ea4233 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Fri, 11 Jan 2019 15:03:40 -0500 Subject: [PATCH] Remove unsafe code --- src/decoder/ifd.rs | 1 + src/decoder/mod.rs | 16 +++++----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/decoder/ifd.rs b/src/decoder/ifd.rs index 930f128..3679e51 100644 --- a/src/decoder/ifd.rs +++ b/src/decoder/ifd.rs @@ -118,6 +118,7 @@ impl Value { } } +#[derive(Clone)] pub struct Entry { type_: Type, count: u32, diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index 006e24c..72fbc70 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -1,5 +1,4 @@ use std::io::{self, Read, Seek}; -use std::mem; use num_traits::{FromPrimitive, Num}; use std::collections::HashMap; use std::string::FromUtf8Error; @@ -343,17 +342,12 @@ impl Decoder { /// Tries to retrieve a tag. /// Return `Ok(None)` if the tag is not present. pub fn find_tag(&mut self, tag: ifd::Tag) -> TiffResult> { - let ifd: &Directory = unsafe { - let ifd = self.ifd.as_ref().unwrap(); // Ok to fail - // Get a immutable borrow of self - // This is ok because entry val only changes the stream - // but not the directory. - mem::transmute_copy(&ifd) + let entry = match self.ifd.as_ref().unwrap().get(&tag) { + None => return Ok(None), + Some(entry) => entry.clone(), }; - match ifd.get(&tag) { - None => Ok(None), - Some(entry) => Ok(Some(try!(entry.val(self)))) - } + + Ok(Some(try!(entry.val(self)))) } /// Tries to retrieve a tag and convert it to the desired type.