Skip to content

Commit

Permalink
fix a math error
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-stones committed Mar 14, 2023
1 parent 1aa3fe8 commit cd245fd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,15 @@ fn check_loader_id(id: &Pubkey) -> bool {
}

fn calculate_heap_cost(heap_size: u64, heap_cost: u64, enable_rounding_fix: bool) -> u64 {
const KILOBYTE: u64 = 1024;
const KIBIBYTE: u64 = 1024;
const PAGE_SIZE_KB: u64 = 32;
let mut rounded_heap_size = heap_size;
if enable_rounding_fix {
rounded_heap_size = rounded_heap_size
.saturating_add(PAGE_SIZE_KB.saturating_sub(1).saturating_mul(KILOBYTE));
.saturating_add(PAGE_SIZE_KB.saturating_mul(KIBIBYTE).saturating_sub(1));
}
rounded_heap_size
.saturating_div(PAGE_SIZE_KB.saturating_mul(KILOBYTE))
.saturating_div(PAGE_SIZE_KB.saturating_mul(KIBIBYTE))
.saturating_sub(1)
.saturating_mul(heap_cost)
}
Expand Down

0 comments on commit cd245fd

Please sign in to comment.