diff --git a/src/block.rs b/src/block.rs index 88475e2..83af087 100644 --- a/src/block.rs +++ b/src/block.rs @@ -61,7 +61,7 @@ impl Address { ) -> Address { let log_diff = log_block_size as isize - S::LOG_SIZE as isize; let top_offset = offset >> S::LOG_SIZE; - let offset = offset >> log_diff; + let offset = offset & ((1 << log_block_size) - 1); let block = block << log_diff | top_offset; Address::new(block, offset as isize) } @@ -187,6 +187,19 @@ impl Sub for Address { mod tests { use super::*; + #[test] + fn conv() { + assert_eq!(Address::::new(0, 1024).into_index(), Some(1024)); + assert_eq!( + Address::::from(1024_usize).into_index(), + Some(1024) + ); + assert_eq!( + Address::::with_block_size(1, 256, 10).into_index(), + Some(1024 + 256) + ); + } + #[test] fn arithmetic() { assert_eq!(