remove error checking :-)

png-branch
an 2019-02-18 23:18:08 -05:00
parent baeea71fe4
commit 1f81a5b043
3 changed files with 23 additions and 43 deletions

View File

@ -180,13 +180,14 @@ fn main() -> ResultS<()>
let mut opt: Options = Default::default(); let mut opt: Options = Default::default();
{ {
let mut ap = ArgumentParser::new();
macro_rules! arg { macro_rules! arg {
($name:expr, $ref:expr, $type:expr, $ap:expr, $desc:expr) => { ($name:expr, $ref:expr, $type:expr, $desc:expr) => {
$ap.refer(&mut $ref).add_option(&[$name], $type, $desc); ap.refer(&mut $ref).add_option(&[$name], $type, $desc);
}; };
} }
let mut ap = ArgumentParser::new();
ap.set_description(env!("CARGO_PKG_DESCRIPTION")); ap.set_description(env!("CARGO_PKG_DESCRIPTION"));
ap.add_option(&["-v", "--version"], ap.add_option(&["-v", "--version"],
@ -198,43 +199,43 @@ fn main() -> ResultS<()>
ap.refer(&mut opt.inputs) ap.refer(&mut opt.inputs)
.add_argument("inputs", Collect, "Input files"); .add_argument("inputs", Collect, "Input files");
arg!("--shp-write-tab", opt.shp_tab, StoreTrue, ap, arg!("--shp-write-tab", opt.shp_tab, StoreTrue,
"shp: Dump all CLUTs as YAML to standard output"); "shp: Dump all CLUTs as YAML to standard output");
arg!("--shp-dump-bitmaps", opt.shp_bmp, StoreTrue, ap, arg!("--shp-dump-bitmaps", opt.shp_bmp, StoreTrue,
"shp: Dump bitmaps into a folder"); "shp: Dump bitmaps into a folder");
arg!("--shp-dump-more-bitmaps", opt.shp_bmp_all, StoreTrue, ap, arg!("--shp-dump-more-bitmaps", opt.shp_bmp_all, StoreTrue,
"shp: Dump all color variations of each bitmap"); "shp: Dump all color variations of each bitmap");
arg!("--shp-write-frm", opt.shp_frm, StoreTrue, ap, arg!("--shp-write-frm", opt.shp_frm, StoreTrue,
"shp: Dump all frames as YAML to standard output"); "shp: Dump all frames as YAML to standard output");
arg!("--shp-write-seq", opt.shp_seq, StoreTrue, ap, arg!("--shp-write-seq", opt.shp_seq, StoreTrue,
"shp: Dump all sequences as YAML to standard output"); "shp: Dump all sequences as YAML to standard output");
arg!("--snd-write", opt.snd_write, StoreTrue, ap, arg!("--snd-write", opt.snd_write, StoreTrue,
"snd: Dump all sound headers as YAML to standard output"); "snd: Dump all sound headers as YAML to standard output");
arg!("--snd-dump", opt.snd_dump, StoreTrue, ap, arg!("--snd-dump", opt.snd_dump, StoreTrue,
"snd: Dump all sounds to WAVE files"); "snd: Dump all sounds to WAVE files");
arg!("--wad-dump-all", opt.wad_all, StoreTrue, ap, arg!("--wad-dump-all", opt.wad_all, StoreTrue,
"wad: Dump all chunks into a folder"); "wad: Dump all chunks into a folder");
arg!("--wad-dump-unknown", opt.wad_unknown, StoreTrue, ap, arg!("--wad-dump-unknown", opt.wad_unknown, StoreTrue,
"wad: Dump all unknown chunks into a folder"); "wad: Dump all unknown chunks into a folder");
arg!("--wad-write-header", opt.wad_header, StoreTrue, ap, arg!("--wad-write-header", opt.wad_header, StoreTrue,
"wad: Dump header info as YAML to standard output"); "wad: Dump header info as YAML to standard output");
arg!("--wad-write-chunks", opt.wad_c_temp, Store, ap, arg!("--wad-write-chunks", opt.wad_c_temp, Store,
"wad: Dump specified chunks in various formats"); "wad: Dump specified chunks in various formats");
arg!("--out-dir", opt.out_dir, Store, ap, arg!("--out-dir", opt.out_dir, Store,
"Sets output directory for dump options"); "Sets output directory for dump options");
arg!("--out-debug", opt.out_debug, StoreTrue, ap, arg!("--out-debug", opt.out_debug, StoreTrue,
"Writes debugging output rather than YAML"); "Writes debugging output rather than YAML");
ap.parse_args_or_exit(); ap.parse_args_or_exit();

View File

@ -23,13 +23,8 @@ fn color(b: &[u8], clut: &mut [ColorShp]) -> ResultS<()>
}?; }?;
let cr = ColorShp::Opaque{r, g, b, l}; let cr = ColorShp::Opaque{r, g, b, l};
clut[i as usize] = cr;
if let Some(cl) = clut.get_mut(i as usize) { Ok(())
*cl = cr;
Ok(())
} else {
bail!("bad index");
}
} }
fn color_tables(b: &[u8], fn color_tables(b: &[u8],
@ -40,10 +35,6 @@ fn color_tables(b: &[u8],
{ {
let end = tab_num * clr_num * 8; let end = tab_num * clr_num * 8;
if b.len() < tab_ofs + end {
bail!("not enough data");
}
let b = &b[tab_ofs..tab_ofs + end]; let b = &b[tab_ofs..tab_ofs + end];
let mut v = vec![vec![ColorShp::Translucent; clr_num]; tab_num]; let mut v = vec![vec![ColorShp::Translucent; clr_num]; tab_num];
@ -97,7 +88,7 @@ fn bitmap(b: &[u8]) -> ResultS<Bitmap>
p += 4; p += 4;
if lst < fst || fst > pitch || lst > pitch || p + end >= b.len() { if lst < fst || fst > pitch || lst > pitch || b.len() < p + end {
bail!("invalid compressed scanline"); bail!("invalid compressed scanline");
} }
@ -115,7 +106,7 @@ fn bitmap(b: &[u8]) -> ResultS<Bitmap>
} }
} else { } else {
// simple copy // simple copy
if p + width * height >= b.len() { if b.len() < p + width * height {
bail!("invalid scanline"); bail!("invalid scanline");
} }
@ -226,21 +217,13 @@ pub fn read_shapes(b: &[u8]) -> ResultS<Vec<CollectionDef>>
} }
let c_lo = if lo_ofs != u32::max_value() as usize { let c_lo = if lo_ofs != u32::max_value() as usize {
if b.len() < lo_ofs + lo_len { Some(collection(&b[lo_ofs..lo_ofs + lo_len])?)
bail!("not enough data");
} else {
Some(collection(&b[lo_ofs..lo_ofs + lo_len])?)
}
} else { } else {
None None
}; };
let c_hi = if hi_ofs != u32::max_value() as usize { let c_hi = if hi_ofs != u32::max_value() as usize {
if b.len() < hi_ofs + hi_len { Some(collection(&b[hi_ofs..hi_ofs + hi_len])?)
bail!("not enough data");
} else {
Some(collection(&b[hi_ofs..hi_ofs + hi_len])?)
}
} else { } else {
None None
}; };

View File

@ -51,10 +51,6 @@ impl Wad<'_>
let index = if !is_old {index} else {i as u16}; let index = if !is_old {index} else {i as u16};
if offset + size > b.len() {
bail!("not enough data for entry");
}
let cnkdata = &b[offset..offset + size]; let cnkdata = &b[offset..offset + size];
let chunks = get_chunks(cnkdata, cnksize)?; let chunks = get_chunks(cnkdata, cnksize)?;
let appdata = &b[p..p + appsize]; let appdata = &b[p..p + appsize];