From 078d7f6ffc0bf912403ea2b775cf1b3ff65cafc4 Mon Sep 17 00:00:00 2001 From: Wan-Teh Chang Date: Mon, 29 Jun 2026 09:49:27 -0700 Subject: [PATCH] Fix Coverity Control flow issues (DEADCODE) Suppose the variable `size` is of the uint64_t type. The condition size > SIZE_MAX is always false if size_t is 64 bits, so the code inside the body of `if (size > SIZE_MAX)` is dead code. Fix Coverity defects CID 561616, CID 561617, CID 561618. Change-Id: I91172896711943bdcec017edce3a9d1e389d9f88 Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8020303 Reviewed-by: Frank Barchard Commit-Queue: Wan-Teh Chang --- source/convert_to_argb.cc | 2 ++ source/scale_argb.cc | 2 ++ source/scale_rgb.cc | 2 ++ 3 files changed, 6 insertions(+) diff --git a/source/convert_to_argb.cc b/source/convert_to_argb.cc index 720cb0984..f3c4018d7 100644 --- a/source/convert_to_argb.cc +++ b/source/convert_to_argb.cc @@ -92,9 +92,11 @@ int ConvertToARGB(const uint8_t* sample, if (need_buf) { const uint64_t rotate_buffer_size = (uint64_t)crop_width * 4 * abs_crop_height; +#if UINT64_MAX > SIZE_MAX if (rotate_buffer_size > SIZE_MAX) { return -1; // Invalid size. } +#endif rotate_buffer = (uint8_t*)malloc((size_t)rotate_buffer_size); if (!rotate_buffer) { return 1; // Out of memory runtime error. diff --git a/source/scale_argb.cc b/source/scale_argb.cc index 4dc446d5e..8758d79c2 100644 --- a/source/scale_argb.cc +++ b/source/scale_argb.cc @@ -844,9 +844,11 @@ int YUVToARGBScaleClip(const uint8_t* src_y, } const int abs_src_height = (src_height < 0) ? -src_height : src_height; const uint64_t argb_buffer_size = (uint64_t)src_width * abs_src_height * 4; +#if UINT64_MAX > SIZE_MAX if (argb_buffer_size > SIZE_MAX) { return -1; // Invalid size. } +#endif uint8_t* argb_buffer = (uint8_t*)malloc((size_t)argb_buffer_size); if (!argb_buffer) { return 1; // Out of memory runtime error. diff --git a/source/scale_rgb.cc b/source/scale_rgb.cc index 6040b364e..0a2f2f6b9 100644 --- a/source/scale_rgb.cc +++ b/source/scale_rgb.cc @@ -53,9 +53,11 @@ int RGBScale(const uint8_t* src_rgb, return -1; // Invalid size. } const uint64_t argb_size = src_argb_size + dst_argb_size; +#if UINT64_MAX > SIZE_MAX if (argb_size > SIZE_MAX) { return -1; // Invalid size. } +#endif uint8_t* src_argb = (uint8_t*)malloc((size_t)argb_size); if (!src_argb) { return 1; // Out of memory runtime error.