diff options
author | kruall <kruall@ydb.tech> | 2025-02-11 19:33:37 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-11 19:33:37 +0300 |
commit | a61d1560c1a93c333b938ba5c0669e8a2c35c927 (patch) | |
tree | c7d1c24ff6e3a2ebee6ea159ce58f967766ae494 | |
parent | 4ac9f23d125ed4bbc5321e0051358c5c6049dc1a (diff) | |
download | ydb-a61d1560c1a93c333b938ba5c0669e8a2c35c927.tar.gz |
Fix underflows in TValueHistory::Accumulate (#14442)
-rw-r--r-- | ydb/library/actors/core/harmonizer/history.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/ydb/library/actors/core/harmonizer/history.h b/ydb/library/actors/core/harmonizer/history.h index 889033dc7d..a1cb3c0ed9 100644 --- a/ydb/library/actors/core/harmonizer/history.h +++ b/ydb/library/actors/core/harmonizer/history.h @@ -34,6 +34,9 @@ struct TValueHistory { double Accumulate(auto op, auto comb, ui8 seconds) const { HARMONIZER_HISTORY_PRINT("Accumulate, seconds = ", static_cast<ui16>(seconds), ", WithTail = ", WithTail); double acc = AccumulatedValue; + if (seconds == 0) { + return acc; + } size_t idx = HistoryIdx; ui8 leftSeconds = seconds; if constexpr (!WithTail) { @@ -46,10 +49,11 @@ struct TValueHistory { } HARMONIZER_HISTORY_PRINT("Accumulate iteration, acc = ", acc, ", idx = ", static_cast<ui16>(idx), ", leftSeconds = ", static_cast<ui16>(leftSeconds)); while (leftSeconds) { - idx--; leftSeconds--; - if (idx >= HistoryBufferSize) { + if (idx == 0) { idx = HistoryBufferSize - 1; + } else { + idx--; } if constexpr (!WithTail) { acc = op(acc, History[idx]); |