Skip to content

Commit

Permalink
add safe guards
Browse files Browse the repository at this point in the history
  • Loading branch information
xuteng0 committed Mar 11, 2024
1 parent 07bd1a4 commit 91ca0c4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions MovingAverage.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ MovingAverage<T, N>::MovingAverage():
_samples(N) {
_result = 0;

// prevent N==0
static_assert(N > 0, "Buffer length must be greater than 0");

while (_samples >> _shift != 1) {
_shift++;
}

_samples = 1 << _shift; //ensure _samples is a power of 2

}

template <class T, uint16_t N>
Expand Down

0 comments on commit 91ca0c4

Please sign in to comment.