Skip to content

Commit

Permalink
fix typecast
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Aug 4, 2023
1 parent 0d4d38d commit 5aa42d2
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions runtime/src/read_only_accounts_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ impl ReadOnlyAccountCacheEntry {
last_time: Self::timestamp(),
}
}
/// lower bits of current timestamp. We don't need higher bits and u32 fits with Index u32
/// lower bits of current timestamp. We don't need higher bits and u32 packs with Index u32 in `ReadOnlyAccountCacheEntry`
fn timestamp() -> u32 {
(timestamp() % (u32::MAX as u64 + 1)) as u32
timestamp() as u32
}
/// ms since `last_time` timestamp
fn ms_since_last_time(&self) -> u32 {
Expand Down Expand Up @@ -285,6 +285,18 @@ mod tests {
/// tests like to deterministically update lru always
const READ_ONLY_CACHE_MS_TO_SKIP_LRU_UPDATE_FOR_TESTS: u32 = 0;

#[test]
fn test_overflow() {
solana_logger::setup();
let l = u32::MAX as u64;
let l = l + 3;
log::error!("{}", (l % (u32::MAX as u64 + 1)) as u32);
log::error!("{}", l as u32);
let l = 3;
log::error!("{}", (l % (u32::MAX as u64 + 1)) as u32);
log::error!("{}", l as u32);
}

#[test]
fn test_read_only_accounts_cache_random() {
const SEED: [u8; 32] = [0xdb; 32];
Expand Down

0 comments on commit 5aa42d2

Please sign in to comment.