mirror of
https://github.com/monero-project/monero.git
synced 2025-05-05 12:45:03 -04:00
Fix overflow issue in epee:misc_utils::rolling_median_t and median(), with unit test
This commit is contained in:
parent
5d850dde99
commit
85efc88c1e
3 changed files with 23 additions and 2 deletions
|
@ -170,6 +170,17 @@ TEST(rolling_median, history_blind)
|
|||
}
|
||||
}
|
||||
|
||||
TEST(rolling_median, overflow)
|
||||
{
|
||||
epee::misc_utils::rolling_median_t<uint64_t> m(2);
|
||||
|
||||
uint64_t over_half = static_cast<uint64_t>(3) << static_cast<uint64_t>(62);
|
||||
m.insert(over_half);
|
||||
m.insert(over_half);
|
||||
ASSERT_EQ((over_half + over_half) < over_half, true);
|
||||
ASSERT_EQ(over_half, m.median());
|
||||
}
|
||||
|
||||
TEST(rolling_median, size)
|
||||
{
|
||||
epee::misc_utils::rolling_median_t<uint64_t> m(10);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue