Skip to content

Commit a61d156

Browse files
authored
Fix underflows in TValueHistory::Accumulate (#14442)
1 parent 4ac9f23 commit a61d156

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ydb/library/actors/core/harmonizer/history.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ struct TValueHistory {
3434
double Accumulate(auto op, auto comb, ui8 seconds) const {
3535
HARMONIZER_HISTORY_PRINT("Accumulate, seconds = ", static_cast<ui16>(seconds), ", WithTail = ", WithTail);
3636
double acc = AccumulatedValue;
37+
if (seconds == 0) {
38+
return acc;
39+
}
3740
size_t idx = HistoryIdx;
3841
ui8 leftSeconds = seconds;
3942
if constexpr (!WithTail) {
@@ -46,10 +49,11 @@ struct TValueHistory {
4649
}
4750
HARMONIZER_HISTORY_PRINT("Accumulate iteration, acc = ", acc, ", idx = ", static_cast<ui16>(idx), ", leftSeconds = ", static_cast<ui16>(leftSeconds));
4851
while (leftSeconds) {
49-
idx--;
5052
leftSeconds--;
51-
if (idx >= HistoryBufferSize) {
53+
if (idx == 0) {
5254
idx = HistoryBufferSize - 1;
55+
} else {
56+
idx--;
5357
}
5458
if constexpr (!WithTail) {
5559
acc = op(acc, History[idx]);

0 commit comments

Comments
 (0)