diff mbox series

[FFmpeg-devel,4/4] avfilter/vf_colormap: Avoid allocation of small array

Message ID AS8PR01MB7944C128E81078851A605E408FFC9@AS8PR01MB7944.eurprd01.prod.exchangelabs.com
State Accepted
Commit 8449fbdf8e7669bfa05df594499dcf4e439561b3
Headers show
Series [FFmpeg-devel,1/4] avfilter/vf_colormap: Properly uninit FFFrameSync, fix leak | 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_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Andreas Rheinhardt April 29, 2022, 1:54 a.m. UTC
The number of elements is always two or three.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavfilter/vf_colormap.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

Comments

Paul B Mahol April 29, 2022, 7 a.m. UTC | #1
whole set lgtm
diff mbox series

Patch

diff --git a/libavfilter/vf_colormap.c b/libavfilter/vf_colormap.c
index d5c5bec39c..106333ced8 100644
--- a/libavfilter/vf_colormap.c
+++ b/libavfilter/vf_colormap.c
@@ -24,6 +24,7 @@ 
  */
 
 #include "libavutil/attributes.h"
+#include "libavutil/avassert.h"
 #include "libavutil/common.h"
 #include "libavutil/opt.h"
 #include "avfilter.h"
@@ -134,20 +135,15 @@  static void gauss_solve_triangular(const double *A, const int *p, double *b, int
 
 static int gauss_solve(double *A, double *b, int n)
 {
-    int *p = av_calloc(n, sizeof(*p));
+    int p[3] = { 0 };
 
-    if (!p)
-        return 1;
+    av_assert2(n <= FF_ARRAY_ELEMS(p));
 
-    if (!gauss_make_triangular(A, p, n)) {
-        av_freep(&p);
+    if (!gauss_make_triangular(A, p, n))
         return 1;
-    }
 
     gauss_solve_triangular(A, p, b, n);
 
-    av_freep(&p);
-
     return 0;
 }