mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #2033 from Gilnaa/panic_2021
Fixed panic!/assert! used with improper format strings
This commit is contained in:
commit
45d70b0c98
2 changed files with 23 additions and 32 deletions
|
@ -166,39 +166,30 @@ mod tests {
|
||||||
let mut input = PeekReader::new(Cursor::new(&data));
|
let mut input = PeekReader::new(Cursor::new(&data));
|
||||||
let mut sut = InputDecoder::new(&mut input, 8, 2, ByteOrder::Little);
|
let mut sut = InputDecoder::new(&mut input, 8, 2, ByteOrder::Little);
|
||||||
|
|
||||||
match sut.peek_read() {
|
// Peek normal length
|
||||||
Ok(mut mem) => {
|
let mut mem = sut.peek_read().unwrap();
|
||||||
assert_eq!(8, mem.length());
|
|
||||||
|
|
||||||
assert_eq!(-2.0, mem.read_float(0, 8));
|
assert_eq!(8, mem.length());
|
||||||
assert_eq!(-2.0, mem.read_float(4, 4));
|
|
||||||
assert_eq!(0xc000000000000000, mem.read_uint(0, 8));
|
|
||||||
assert_eq!(0xc0000000, mem.read_uint(4, 4));
|
|
||||||
assert_eq!(0xc000, mem.read_uint(6, 2));
|
|
||||||
assert_eq!(0xc0, mem.read_uint(7, 1));
|
|
||||||
assert_eq!(&[0, 0xc0], mem.get_buffer(6));
|
|
||||||
assert_eq!(&[0, 0xc0, 0xff, 0xff], mem.get_full_buffer(6));
|
|
||||||
|
|
||||||
let mut copy: Vec<u8> = Vec::new();
|
assert_eq!(-2.0, mem.read_float(0, 8));
|
||||||
mem.clone_buffer(&mut copy);
|
assert_eq!(-2.0, mem.read_float(4, 4));
|
||||||
assert_eq!(vec![0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0], copy);
|
assert_eq!(0xc000000000000000, mem.read_uint(0, 8));
|
||||||
|
assert_eq!(0xc0000000, mem.read_uint(4, 4));
|
||||||
|
assert_eq!(0xc000, mem.read_uint(6, 2));
|
||||||
|
assert_eq!(0xc0, mem.read_uint(7, 1));
|
||||||
|
assert_eq!(&[0, 0xc0], mem.get_buffer(6));
|
||||||
|
assert_eq!(&[0, 0xc0, 0xff, 0xff], mem.get_full_buffer(6));
|
||||||
|
|
||||||
mem.zero_out_buffer(7, 8);
|
let mut copy: Vec<u8> = Vec::new();
|
||||||
assert_eq!(&[0, 0, 0xff, 0xff], mem.get_full_buffer(6));
|
mem.clone_buffer(&mut copy);
|
||||||
}
|
assert_eq!(vec![0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0], copy);
|
||||||
Err(e) => {
|
|
||||||
assert!(false, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match sut.peek_read() {
|
mem.zero_out_buffer(7, 8);
|
||||||
Ok(mem) => {
|
assert_eq!(&[0, 0, 0xff, 0xff], mem.get_full_buffer(6));
|
||||||
assert_eq!(2, mem.length());
|
|
||||||
assert_eq!(0xffff, mem.read_uint(0, 2));
|
// Peek tail
|
||||||
}
|
let mem = sut.peek_read().unwrap();
|
||||||
Err(e) => {
|
assert_eq!(2, mem.length());
|
||||||
assert!(false, e);
|
assert_eq!(0xffff, mem.read_uint(0, 2));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ macro_rules! safe_write(
|
||||||
($fd:expr, $($args:tt)+) => (
|
($fd:expr, $($args:tt)+) => (
|
||||||
match write!($fd, $($args)+) {
|
match write!($fd, $($args)+) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(f) => panic!(f.to_string())
|
Err(f) => panic!("{}", f)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -118,7 +118,7 @@ macro_rules! safe_writeln(
|
||||||
($fd:expr, $($args:tt)+) => (
|
($fd:expr, $($args:tt)+) => (
|
||||||
match writeln!($fd, $($args)+) {
|
match writeln!($fd, $($args)+) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(f) => panic!(f.to_string())
|
Err(f) => panic!("{}", f)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue