From 85efc88c1edc7371ca5c8722c896fd64a258ddd2 Mon Sep 17 00:00:00 2001 From: koe Date: Tue, 21 Jul 2020 02:00:27 -0500 Subject: Fix overflow issue in epee:misc_utils::rolling_median_t and median(), with unit test --- tests/unit_tests/rolling_median.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/unit_tests/rolling_median.cpp b/tests/unit_tests/rolling_median.cpp index 730f1e7c5..d415c5b95 100644 --- a/tests/unit_tests/rolling_median.cpp +++ b/tests/unit_tests/rolling_median.cpp @@ -170,6 +170,17 @@ TEST(rolling_median, history_blind) } } +TEST(rolling_median, overflow) +{ + epee::misc_utils::rolling_median_t m(2); + + uint64_t over_half = static_cast(3) << static_cast(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 m(10); -- cgit v1.2.3