Change an operation order to avoid uint32 overflow
Also added a clamp to prevent from dividing by zero.
BUG=aomedia:2537
Change-Id: I2c843049f29f525b42cee7ddcbd3c2c66838d776
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index e0e82e4..8e40e80 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -1705,9 +1705,9 @@
RATE_CONTROL *const rc = &cpi->rc;
int64_t vbr_bits_off_target = rc->vbr_bits_off_target;
int max_delta;
- const int frame_window =
- AOMMIN(16, (int)cpi->twopass.total_stats.count -
- cpi->common.current_frame.frame_number);
+ const int frame_window = clamp((int)(cpi->twopass.total_stats.count -
+ cpi->common.current_frame.frame_number),
+ 1, 16);
max_delta = (vbr_bits_off_target > 0)
? (int)(vbr_bits_off_target / frame_window)