diff --git a/src/durandal/bin.rs b/src/durandal/bin.rs index d2284d3..517723a 100644 --- a/src/durandal/bin.rs +++ b/src/durandal/bin.rs @@ -35,19 +35,19 @@ impl BinUtil for [u8] { fn c_iden(&self, i: usize) -> ResultS { - if i + 3 >= self.len() {return err_msg("not enough data")} + if i + 3 >= self.len() {return Err(err_msg("not enough data"));} Ok([self[i], self[i+1], self[i+2], self[i+3]]) } fn c_u32b(&self, i: usize) -> ResultS { - if i + 3 >= self.len() {return err_msg("not enough data")} + if i + 3 >= self.len() {return Err(err_msg("not enough data"));} Ok(u32::from_be_bytes([self[i], self[i+1], self[i+2], self[i+3]])) } fn c_u16b(&self, i: usize) -> ResultS { - if i + 1 >= self.len() {return err_msg("not enough data")} + if i + 1 >= self.len() {return Err(err_msg("not enough data"));} Ok(u16::from_be_bytes([self[i], self[i+1]])) } } diff --git a/src/durandal/err.rs b/src/durandal/err.rs index 8fb0396..caf7df1 100644 --- a/src/durandal/err.rs +++ b/src/durandal/err.rs @@ -1,6 +1,6 @@ //! Error handling. -pub use failure::{Error, Fail, format_err}; +pub use failure::{Error, Fail, err_msg, format_err}; use crate::durandal::traits::PrimInt; use std::fmt; @@ -24,7 +24,4 @@ impl fmt::Debug for ReprError where T: PrimInt pub type ResultS = Result; -pub fn err_msg(s: &'static str) -> ResultS {Err(failure::err_msg(s))} -pub fn err_msg_v (s: &'static str) -> Error { failure::err_msg(s) } - // EOF diff --git a/src/marathon/pict.rs b/src/marathon/pict.rs index ab94c4f..6c0b4d2 100644 --- a/src/marathon/pict.rs +++ b/src/marathon/pict.rs @@ -34,10 +34,10 @@ pub fn read_bitmap_area(mut im: Image, b: &[u8], packed: bool, clip: bool) -> Re // clut_id = b.c_u32b(p+38)?; if pitch_fl & 0x8000 == 0 { - return err_msg("PICT1 not supported"); + return Err(err_msg("PICT1 not supported")); } if right - left != w || bottom - top != h { - return err_msg("image bounds are incorrect"); + return Err(err_msg("image bounds are incorrect")); } p += 46; // size of header @@ -63,7 +63,7 @@ pub fn read_bitmap_area(mut im: Image, b: &[u8], packed: bool, clip: bool) -> Re match depth { 1 | 2 | 4 | 8 => { - let clut = clut.ok_or_else(|| err_msg_v("no clut in indexed mode"))?; + let clut = clut.ok_or_else(|| err_msg("no clut in indexed mode"))?; if pitch < 8 && depth == 8 { // uncompressed 8-bit colormap indices for _ in 0..h { @@ -86,7 +86,7 @@ pub fn read_bitmap_area(mut im: Image, b: &[u8], packed: bool, clip: bool) -> Re Ok(im) } - else {err_msg("invalid configuration")} + else {Err(err_msg("invalid configuration"))} }, 16 => if pitch < 8 || pack_typ == PACK_NONE { @@ -110,7 +110,7 @@ pub fn read_bitmap_area(mut im: Image, b: &[u8], packed: bool, clip: bool) -> Re Ok(im) } - else {err_msg("invalid configuration")}, + else {Err(err_msg("invalid configuration"))}, 32 => if pitch < 8 || pack_typ == PACK_NONE || pack_typ == PACK_NOPAD { // uncompressed RGB8 or XRGB8 @@ -140,8 +140,8 @@ pub fn read_bitmap_area(mut im: Image, b: &[u8], packed: bool, clip: bool) -> Re Ok(im) } - else {err_msg("invalid configuration")}, - _ => err_msg("invalid bit depth") + else {Err(err_msg("invalid configuration"))}, + _ => Err(err_msg("invalid bit depth")) } } @@ -222,11 +222,11 @@ pub fn load_pict(b: &[u8]) -> ResultS 0x00a1 => p += (b.c_u16b(p+2)? & !1) as usize + 2, // LongComment 0x100..= 0x7fff => p += (op >> 8) as usize * 2, // Reserved - _ => return err_msg("invalid op in PICT") + _ => return Err(err_msg("invalid op in PICT")) } } - err_msg("no image in data") + Err(err_msg("no image in data")) } /// Read a colorTable structure. @@ -246,7 +246,7 @@ pub fn get_clut(b: &[u8]) -> ResultS<(Vec, usize)> let g = b[p+4]; let b = b[p+6]; - if n >= clut.len() {return err_msg("bad clut index");} + if n >= clut.len() {return Err(err_msg("bad clut index"));} clut[n] = Color{r, g, b, a: 255}; p += 8; @@ -275,7 +275,7 @@ pub fn read_rle(b: &[u8], pitch: usize, ln: bool) -> ResultS<(Vec, usize)> } if o.len() == pitch {Ok((o, p))} - else {err_msg("incorrect size for compressed scanline")} + else {Err(err_msg("incorrect size for compressed scanline"))} } /// Read a sequence of packed RLE data. @@ -298,7 +298,7 @@ pub fn expand_data(b: Vec, depth: u16) -> ResultS> 4 => b.len() * 2, 2 => b.len() * 4, 1 => b.len() * 8, - _ => return err_msg("invalid bit depth") + _ => return Err(err_msg("invalid bit depth")) }); for ch in b { @@ -306,7 +306,7 @@ pub fn expand_data(b: Vec, depth: u16) -> ResultS> 4 => for i in 1..=0 {o.push(ch >> i * 4 & 0xfu8);}, // 2 nibbles 2 => for i in 3..=0 {o.push(ch >> i * 2 & 0x3u8);}, // 4 dibits 1 => for i in 7..=0 {o.push(ch >> i * 1 & 0x1u8);}, // 8 bits - _ => return err_msg("invalid bit depth") + _ => return Err(err_msg("invalid bit depth")) } } diff --git a/src/marathon/wad.rs b/src/marathon/wad.rs index cd61da4..ab057c8 100644 --- a/src/marathon/wad.rs +++ b/src/marathon/wad.rs @@ -7,7 +7,7 @@ impl Wad<'_> { pub fn new(b: &[u8]) -> ResultS { - if b.len() < 128 {return err_msg("not enough data for Wad header");} + if b.len() < 128 {return Err(err_msg("not enough data for Wad header"));} let wadver = b.c_u16b( 0)?; let dataver = b.c_u16b( 2)?; @@ -32,7 +32,7 @@ impl Wad<'_> let size = b.c_u32b(p+4)? as usize; let index = if !is_old {b.c_u16b(p+8)?} else {i as u16}; - if offset + size > b.len() {return err_msg("not enough data for entry");} + if offset + size > b.len() {return Err(err_msg("not enough data for entry"));} let chunks = get_chunks(&b[offset..offset+size], is_old)?; let appdata = &b[p..p+appsize]; @@ -94,7 +94,7 @@ c_enum! { 0 => Base, 1 => Dir, 2 => Over, - 4 => MI, + 4 => Inf, } }