Commit 38f289ba9f for aom

commit 38f289ba9f9206dc7aa20edda24116f366bba0e3
Author: Jingning Han <jingning@google.com>
Date:   Thu Dec 3 09:23:17 2026 -0800

    Fix Coverity defects CID 567688, 567689, 567690

    - CID 567690 (FORWARD_NULL) in get_or_reset_pmc_rd(): assert the newly
      allocated PICK_MODE_CONTEXT is not null after the allocation failure
      check. aom_internal_error() does not return in the encoder because
      setjmp() is always set up.
    - CID 567689 (SIZEOF_MISMATCH) in aom_calloc(): pass the alignment to
      align_and_set_malloc_addr() through a local size_t variable instead of
      DEFAULT_ALIGNMENT, which expands to 2 * sizeof(void *).
    - CID 567688 (OVERFLOW_BEFORE_WIDEN) in av1_sub_sum_sse_lbd_c(): compute
      d * d in 64-bit arithmetic. d is in [-255, 255], so the 32-bit product
      could not actually overflow.

    No functional change.

    Change-Id: Iabfb6896f0ff7856070d9b69506ab24aab84a452

diff --git a/aom_mem/aom_mem.c b/aom_mem/aom_mem.c
index 9ceb18bd25..f92d07fec8 100644
--- a/aom_mem/aom_mem.c
+++ b/aom_mem/aom_mem.c
@@ -71,16 +71,16 @@ void *aom_memalign(size_t align, size_t size) {
 void *aom_malloc(size_t size) { return aom_memalign(DEFAULT_ALIGNMENT, size); }

 void *aom_calloc(size_t num, size_t size) {
-  if (!check_size_argument_overflow(num, size, DEFAULT_ALIGNMENT)) return NULL;
+  const size_t align = DEFAULT_ALIGNMENT;
+  if (!check_size_argument_overflow(num, size, align)) return NULL;
   const size_t total_size = num * size;
-  const size_t aligned_size =
-      total_size + GetAllocationPaddingSize(DEFAULT_ALIGNMENT);
+  const size_t aligned_size = total_size + GetAllocationPaddingSize(align);
   // Use calloc() for larger buffers so freshly mapped/sbrk'd pages avoid an
   // explicit zero-fill pass; keep malloc() + memset() for small buffers.
   const int use_calloc = aligned_size > 4096;
   void *const addr =
       use_calloc ? calloc(1, aligned_size) : malloc(aligned_size);
-  void *const x = align_and_set_malloc_addr(addr, DEFAULT_ALIGNMENT);
+  void *const x = align_and_set_malloc_addr(addr, align);
   if (x && !use_calloc) {
     memset(x, 0, total_size);
   }
diff --git a/av1/encoder/partition_search.c b/av1/encoder/partition_search.c
index 23444a4c85..6979b75aff 100644
--- a/av1/encoder/partition_search.c
+++ b/av1/encoder/partition_search.c
@@ -1775,6 +1775,9 @@ static PICK_MODE_CONTEXT *get_or_reset_pmc_rd(const AV1_COMP *cpi,
       aom_internal_error(td->mb.e_mbd.error_info, AOM_CODEC_MEM_ERROR,
                          "Failed to allocate PICK_MODE_CONTEXT");
     }
+    // aom_internal_error() does not return here because the encoder always
+    // sets up setjmp() before encoding.
+    assert(*ctx != NULL);
   } else {
     assert((*ctx)->num_4x4_blk ==
            (block_size_wide[bsize] * block_size_high[bsize]) / 16);
diff --git a/av1/encoder/tx_search.c b/av1/encoder/tx_search.c
index 61e211398e..0344b4166a 100644
--- a/av1/encoder/tx_search.c
+++ b/av1/encoder/tx_search.c
@@ -149,7 +149,7 @@ uint64_t av1_sub_sum_sse_lbd_c(const uint8_t *src, int src_stride,
       const int d = (int)sr[c] - (int)dr[c];
       fr[c] = (int16_t)d;
       acc_sum += d;
-      sse += (uint64_t)(d * d);
+      sse += (uint64_t)((int64_t)d * d);
     }
   }
   *sum = acc_sum;