diff mbox series

[FFmpeg-devel] avcodec/elbg: Increase some fields to 64bit

Message ID 20210606220458.32440-1-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel] avcodec/elbg: Increase some fields to 64bit
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Michael Niedermayer June 6, 2021, 10:04 p.m. UTC
Fixes: Ticket8312
Fixes: Ticket8321

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/elbg.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/elbg.c b/libavcodec/elbg.c
index b6049c938b..63659dda8b 100644
--- a/libavcodec/elbg.c
+++ b/libavcodec/elbg.c
@@ -45,12 +45,12 @@  typedef struct cell_s {
  * ELBG internal data
  */
 typedef struct elbg_data {
-    int error;
+    int64_t error;
     int dim;
     int numCB;
     int *codebook;
     cell **cells;
-    int *utility;
+    int64_t *utility;
     int64_t *utility_inc;
     int *nearest_cb;
     int *points;
@@ -265,7 +265,8 @@  static void update_utility_and_n_cb(elbg_data *elbg, int idx, int newutility)
  */
 static void try_shift_candidate(elbg_data *elbg, int idx[3])
 {
-    int j, k, olderror=0, newerror, cont=0;
+    int j, k, cont=0;
+    int64_t olderror=0, newerror;
     int newutility[3];
     int *newcentroid[3] = {
         elbg->scratchbuf,
@@ -375,19 +376,20 @@  int avpriv_do_elbg(int *points, int dim, int numpoints, int *codebook,
     int dist;
     elbg_data elbg_d;
     elbg_data *elbg = &elbg_d;
-    int i, j, k, last_error, steps = 0, ret = 0;
+    int i, j, k, steps = 0, ret = 0;
     int *dist_cb = av_malloc_array(numpoints, sizeof(int));
     int *size_part = av_malloc_array(numCB, sizeof(int));
     cell *list_buffer = av_malloc_array(numpoints, sizeof(cell));
     cell *free_cells;
     int best_dist, best_idx = 0;
+    int64_t last_error;
 
-    elbg->error = INT_MAX;
+    elbg->error = INT64_MAX;
     elbg->dim = dim;
     elbg->numCB = numCB;
     elbg->codebook = codebook;
     elbg->cells = av_malloc_array(numCB, sizeof(cell *));
-    elbg->utility = av_malloc_array(numCB, sizeof(int));
+    elbg->utility = av_malloc_array(numCB, sizeof(*elbg->utility));
     elbg->nearest_cb = closest_cb;
     elbg->points = points;
     elbg->utility_inc = av_malloc_array(numCB, sizeof(*elbg->utility_inc));
@@ -405,7 +407,7 @@  int avpriv_do_elbg(int *points, int dim, int numpoints, int *codebook,
         free_cells = list_buffer;
         last_error = elbg->error;
         steps++;
-        memset(elbg->utility, 0, numCB*sizeof(int));
+        memset(elbg->utility, 0, numCB*sizeof(*elbg->utility));
         memset(elbg->cells, 0, numCB*sizeof(cell *));
 
         elbg->error = 0;