diff mbox series

[FFmpeg-devel,222/223] avcodec/mlpenc: Add const where appropriate

Message ID 20201203003628.778278-5-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,01/45] avcodec/a64multienc: Fix memleak upon init failure
Related show

Checks

Context Check Description
andriy/x86 warning Failed to apply patch

Commit Message

Andreas Rheinhardt Dec. 3, 2020, 12:36 a.m. UTC
The MLP/TrueHD encoder uses pointers to non-const to access several
static objects that are only initialized at runtime and are therefore
not declared as const. This does not result in compiler warnings, but it
is fragile, as these objects are really not to be modified as they are
not owned by any encoder instance. Therefore this commit adds const to
the pointed to type of the pointers used to access them after their
initialization. One object has even been made const.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/mlpenc.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index f6159d39c8..dfd1cc8d60 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -190,8 +190,8 @@  typedef struct {
     unsigned int    number_of_subblocks;
     unsigned int    seq_index;              ///< Sequence index for high compression levels.
 
-    ChannelParams  *prev_channel_params;
-    DecodingParams *prev_decoding_params;
+    const ChannelParams  *prev_channel_params;
+    const DecodingParams *prev_decoding_params;
 
     ChannelParams  *seq_channel_params;
     DecodingParams *seq_decoding_params;
@@ -203,7 +203,7 @@  typedef struct {
 
 static ChannelParams   restart_channel_params[MAX_CHANNELS];
 static DecodingParams  restart_decoding_params[MAX_SUBSTREAMS];
-static BestOffset      restart_best_offset[NUM_CODEBOOKS] = {{0}};
+static const BestOffset restart_best_offset[NUM_CODEBOOKS] = {{0}};
 
 #define SYNC_MAJOR      0xf8726f
 #define MAJOR_SYNC_INFO_SIGNATURE   0xB752
@@ -285,9 +285,9 @@  static int compare_matrix_params(MLPEncodeContext *ctx, const MatrixParams *prev
  */
 static int compare_decoding_params(MLPEncodeContext *ctx)
 {
-    DecodingParams *prev = ctx->prev_decoding_params;
+    const DecodingParams *prev = ctx->prev_decoding_params;
     DecodingParams *dp = ctx->cur_decoding_params;
-    MatrixParams *prev_mp = &prev->matrix_params;
+    const MatrixParams *prev_mp = &prev->matrix_params;
     MatrixParams *mp = &dp->matrix_params;
     RestartHeader  *rh = ctx->cur_restart_header;
     unsigned int ch;
@@ -315,7 +315,7 @@  static int compare_decoding_params(MLPEncodeContext *ctx)
         }
 
     for (ch = rh->min_channel; ch <= rh->max_channel; ch++) {
-        ChannelParams *prev_cp = &ctx->prev_channel_params[ch];
+        const ChannelParams *prev_cp = &ctx->prev_channel_params[ch];
         ChannelParams *cp = &ctx->cur_channel_params[ch];
 
         if (!(retval & PARAM_FIR) &&
@@ -1967,7 +1967,7 @@  static void clear_path_counter(PathCounter *path_counter)
     }
 }
 
-static int compare_best_offset(BestOffset *prev, BestOffset *cur)
+static int compare_best_offset(const BestOffset *prev, const BestOffset *cur)
 {
     if (prev->lsb_bits != cur->lsb_bits)
         return 1;
@@ -1978,7 +1978,8 @@  static int compare_best_offset(BestOffset *prev, BestOffset *cur)
 static int best_codebook_path_cost(MLPEncodeContext *ctx, unsigned int channel,
                                    PathCounter *src, int cur_codebook)
 {
-    BestOffset *cur_bo, *prev_bo = restart_best_offset;
+    const BestOffset *prev_bo = restart_best_offset;
+    BestOffset *cur_bo;
     int bitcount = src->bitcount;
     char *path = src->path + 1;
     int prev_codebook;
@@ -2007,7 +2008,8 @@  static void set_best_codebook(MLPEncodeContext *ctx)
     unsigned int channel;
 
     for (channel = rh->min_channel; channel <= rh->max_channel; channel++) {
-        BestOffset *cur_bo, *prev_bo = restart_best_offset;
+        const BestOffset *prev_bo = restart_best_offset;
+        BestOffset *cur_bo;
         PathCounter path_counter[NUM_CODEBOOKS + 1];
         unsigned int best_codebook;
         unsigned int index;