[FFmpeg-devel] [PATCH v2 6/7] mlpenc: fix -fsanitize=integer errors

Jai Luthra me at jailuthra.in
Mon Feb 3 20:55:52 EET 2020


Signed-off-by: Jai Luthra <me at jailuthra.in>
---
 libavcodec/mlpenc.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

    v2: fixes more integer issues

diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index 347a43248c..173cf71956 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -87,11 +87,11 @@ typedef struct {
 } DecodingParams;
 
 typedef struct BestOffset {
-    int16_t offset;
+    int32_t offset;
     int bitcount;
     int lsb_bits;
-    int16_t min;
-    int16_t max;
+    int32_t min;
+    int32_t max;
 } BestOffset;
 
 #define HUFF_OFFSET_MIN    (-16384)
@@ -568,7 +568,7 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
     }
     ctx->coded_sample_fmt[1] = -1 & 0xf;
 
-    ctx->dts = -avctx->frame_size;
+    ctx->dts = (uint16_t) (-avctx->frame_size);
 
     ctx->num_channels = avctx->channels + 2; /* +2 noise channels */
     ctx->one_sample_buffer_size = avctx->frame_size
@@ -1249,7 +1249,7 @@ static void input_data_internal(MLPEncodeContext *ctx, const uint8_t *samples,
                 uint32_t abs_sample;
                 int32_t sample;
 
-                sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256U;
+                sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256;
 
                 /* TODO Find out if number_sbits can be used for negative values. */
                 abs_sample = FFABS(sample);
@@ -1589,7 +1589,7 @@ static void no_codebook_bits(MLPEncodeContext *ctx,
                              BestOffset *bo)
 {
     DecodingParams *dp = ctx->cur_decoding_params;
-    int16_t offset;
+    int32_t offset;
     int32_t unsign = 0;
     uint32_t diff;
     int lsb_bits;
@@ -1611,7 +1611,7 @@ static void no_codebook_bits(MLPEncodeContext *ctx,
 
     /* If all samples are the same (lsb_bits == 0), offset must be
      * adjusted because of sign_shift. */
-    offset = min + diff / 2 + !!lsb_bits;
+    offset = min + (int) (diff / 2) + !!lsb_bits;
 
     bo->offset   = offset;
     bo->lsb_bits = lsb_bits;
@@ -1792,7 +1792,7 @@ static void determine_bits(MLPEncodeContext *ctx)
 #define SAMPLE_MAX(bitdepth) ((1 << (bitdepth - 1)) - 1)
 #define SAMPLE_MIN(bitdepth) (~SAMPLE_MAX(bitdepth))
 
-#define MSB_MASK(bits)  (-(1u << (bits)))
+#define MSB_MASK(bits)  (-(int)(1u << (bits)))
 
 /** Applies the filter to the current samples, and saves the residual back
  *  into the samples buffer. If the filter is too bad and overflows the
@@ -2280,8 +2280,8 @@ static int mlp_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 
     bytes_written = write_access_unit(ctx, avpkt->data, avpkt->size, restart_frame);
 
-    ctx->timestamp += ctx->frame_size[ctx->frame_index];
-    ctx->dts       += ctx->frame_size[ctx->frame_index];
+    ctx->timestamp = (uint16_t) (ctx->timestamp + ctx->frame_size[ctx->frame_index]);
+    ctx->dts       = (uint16_t) (ctx->dts       + ctx->frame_size[ctx->frame_index]);
 
 input_and_return:
 
-- 
2.25.0



More information about the ffmpeg-devel mailing list