Skip to content

Commit

Permalink
Fix underflows in TValueHistory::Accumulate (#14442)
Browse files Browse the repository at this point in the history
  • Loading branch information
kruall authored Feb 11, 2025
1 parent 4ac9f23 commit a61d156
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ydb/library/actors/core/harmonizer/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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]);
Expand Down

0 comments on commit a61d156

Please sign in to comment.