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 --- contrib/epee/include/rolling_median.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'contrib/epee/include/rolling_median.h') diff --git a/contrib/epee/include/rolling_median.h b/contrib/epee/include/rolling_median.h index 11275aa70..088a71d3e 100644 --- a/contrib/epee/include/rolling_median.h +++ b/contrib/epee/include/rolling_median.h @@ -34,6 +34,8 @@ #pragma once +#include "misc_language.h" + #include #include @@ -226,7 +228,7 @@ public: Item v = data[heap[0]]; if (minCt < maxCt) { - v = (v + data[heap[-1]]) / 2; + v = get_mid(v, data[heap[-1]]); } return v; } -- cgit v1.2.3