aom: Avoid an int cast of double in vbr_rate_correction

From fd4b24a1a854f845f409dd165749e2bb285f2c75 Mon Sep 17 00:00:00 2001
From: Wan-Teh Chang <[EMAIL REDACTED]>
Date: Mon, 1 Jul 2024 14:06:53 -0700
Subject: [PATCH] Avoid an int cast of double in vbr_rate_correction

In the calculation of frame_window, avoid the int cast of
cpi->ppi->twopass.stats_buf_ctx->total_stats->count (a double) because
in theory it could be greater than INT_MAX. Use the int cast on the
result of AOMMIN(16, ...), which is <= 16

This is equivalent to the first change in the libvpx CL
https://chromium-review.googlesource.com/c/webm/libvpx/+/5670633.

Change-Id: Iced2e32aceb9e3be1505a9ef89494bc499afedaf
---
 av1/encoder/ratectrl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index cd73772b46..744f5f5cdc 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -2598,12 +2598,12 @@ static void vbr_rate_correction(AV1_COMP *cpi, int *this_frame_target) {
 #endif
   int64_t frame_target = *this_frame_target;
 
-  const int stats_count =
+  const double stats_count =
       cpi->ppi->twopass.stats_buf_ctx->total_stats != NULL
-          ? (int)cpi->ppi->twopass.stats_buf_ctx->total_stats->count
-          : 0;
-  const int frame_window = AOMMIN(
-      16, (int)(stats_count - (int)cpi->common.current_frame.frame_number));
+          ? cpi->ppi->twopass.stats_buf_ctx->total_stats->count
+          : 0.0;
+  const int frame_window =
+      (int)AOMMIN(16, stats_count - cpi->common.current_frame.frame_number);
   assert(VBR_PCT_ADJUSTMENT_LIMIT <= 100);
   if (frame_window > 0) {
     const int64_t max_delta =