fix `Address::sub`

pull/3/head
Szymon Walter 2018-03-20 12:38:22 +01:00
parent 764c4de6bf
commit fbdbeb2842
2 changed files with 6 additions and 1 deletions

View File

@ -177,7 +177,7 @@ impl<S: Size> Sub for Address<S> {
type Output = Address<S>;
fn sub(self, rhs: Address<S>) -> Address<S> {
Address::new(
self.block + rhs.block,
self.block - rhs.block,
self.offset as isize - rhs.offset as isize,
)
}

View File

@ -229,6 +229,11 @@ mod tests {
#[test]
fn file_len() {
let file = RefCell::new(File::open("ext2.img").unwrap());
assert_eq!(
Address::<Size512>::from(2048_usize)
- Address::<Size512>::from(1024_usize),
Address::<Size512>::new(2, 0)
);
assert_eq!(
unsafe {
file.slice_unchecked(