From 648f6fd23e236d3726f5976339d150f6108a9ab0 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Tue, 30 Apr 2024 17:32:53 +0200 Subject: [PATCH] protected cumulative_stats against count wraparound --- include/boost/unordered/detail/cumulative_stats.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/boost/unordered/detail/cumulative_stats.hpp b/include/boost/unordered/detail/cumulative_stats.hpp index 8be500c1..288f752c 100644 --- a/include/boost/unordered/detail/cumulative_stats.hpp +++ b/include/boost/unordered/detail/cumulative_stats.hpp @@ -77,8 +77,12 @@ public: static_assert( sizeof...(Ts)==N,"A sample must be provided for each sequence."); + if(BOOST_UNLIKELY(++n==0)){ /* wraparound */ + reset(); + n=1; + } mp11::tuple_transform( - welfords_algorithm{++n}, + welfords_algorithm{n}, std::forward_as_tuple(std::forward(xs)...), data); }