More tests on out-of-range accesses around unsafe code.
This commit is contained in:
parent
4f2e54a6b9
commit
b66b47d1fd
|
@ -130,4 +130,13 @@ mod tests {
|
||||||
fn out_of_range() {
|
fn out_of_range() {
|
||||||
BigEndian::loadu16(&[0x01, 0x02], 1);
|
BigEndian::loadu16(&[0x01, 0x02], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "attempt to add with overflow" with the arithmetic overflow
|
||||||
|
// check, and "slice index starts at 18446744073709551615 but ends
|
||||||
|
// at 1" without it.
|
||||||
|
#[test]
|
||||||
|
#[should_panic(expected = "at")]
|
||||||
|
fn wrap_around() {
|
||||||
|
BigEndian::loadu16(&[0x01, 0x02], (-1isize) as usize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,6 +229,7 @@ fn parse_unknown<'a>(data: &'a [u8], offset: usize, count: usize)
|
||||||
mod tests {
|
mod tests {
|
||||||
use endian::BigEndian;
|
use endian::BigEndian;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use super::parse_short;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn byte() {
|
fn byte() {
|
||||||
|
@ -448,4 +449,12 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These functions are never called in a way that an out-of-range access
|
||||||
|
// could happen, so this test is hypothetical but just for safety.
|
||||||
|
#[test]
|
||||||
|
#[should_panic(expected = "index 5 out of range for slice of length 4")]
|
||||||
|
fn short_oor() {
|
||||||
|
parse_short::<BigEndian>(b"\x01\x02\x03\x04", 1, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue