diff mbox series

[FFmpeg-devel] tests/checkasm/nlmeans: Add check for av_calloc

Message ID 20220216094203.2288551-1-jiasheng@iscas.ac.cn
State New
Headers show
Series [FFmpeg-devel] tests/checkasm/nlmeans: Add check for av_calloc | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Jiasheng Jiang Feb. 16, 2022, 9:42 a.m. UTC
As the potential failure of the av_calloc(), it should be better
to check it and fail() if fails in order to avoid the dereference
of the NULL pointer.

Fixes: f679711c1b ("checkasm: add vf_nlmeans test for ssd_integral_image")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 tests/checkasm/vf_nlmeans.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tests/checkasm/vf_nlmeans.c b/tests/checkasm/vf_nlmeans.c
index 87474d6803..82370bbeec 100644
--- a/tests/checkasm/vf_nlmeans.c
+++ b/tests/checkasm/vf_nlmeans.c
@@ -47,9 +47,9 @@  void checkasm_check_nlmeans(void)
         const int ii_h = h + e*2;
         const int ii_lz_32 = FFALIGN(ii_w + 1, 4);
         uint32_t *ii_orig_ref = av_calloc(ii_h + 1, ii_lz_32 * sizeof(*ii_orig_ref));
-        uint32_t *ii_ref = ii_orig_ref + ii_lz_32 + 1;
+        uint32_t *ii_ref;
         uint32_t *ii_orig_new = av_calloc(ii_h + 1, ii_lz_32 * sizeof(*ii_orig_new));
-        uint32_t *ii_new = ii_orig_new + ii_lz_32 + 1;
+        uint32_t *ii_new;
         const int src_lz = FFALIGN(w, 16);
         uint8_t *src = av_calloc(h, src_lz);
 
@@ -58,6 +58,16 @@  void checkasm_check_nlmeans(void)
                      const uint8_t *s2, ptrdiff_t linesize2,
                      int w, int h);
 
+        if (!ii_orig_ref || !ii_orig_new || !src) {
+            av_free(ii_orig_ref);
+            av_free(ii_orig_new);
+            av_free(src);
+            fail();
+        }
+
+        ii_ref = ii_orig_ref + ii_lz_32 + 1;
+        ii_new = ii_orig_new + ii_lz_32 + 1;
+
         randomize_buffer(src, h * src_lz);
 
         for (offy = -r; offy <= r; offy++) {