Use wrapping_sub and update expr

This commit is contained in:
wtfsck 2021-05-10 18:44:06 +02:00
parent af14398080
commit b4d7c67fae
2 changed files with 3 additions and 2 deletions

View File

@ -63,7 +63,7 @@ impl Block {
if self.valid_data.is_empty() {
return Ok(());
}
for _ in 0..self.valid_data_address_aligned - self.valid_data_address {
for _ in 0..self.valid_data_address_aligned.wrapping_sub(self.valid_data_address) {
self.encoder.write_byte_internal(0xCC);
}
match self.alignment {

View File

@ -42,7 +42,8 @@ pub(super) trait Instr {
}
fn correct_diff(in_block: bool, diff: i64, gained: u64) -> i64 {
if in_block && diff >= gained as i64 {
if in_block && diff >= 0 {
debug_assert!(diff as u64 >= gained);
diff - gained as i64
} else {
diff