mlpenc: prevent negative lsb_bits lshift

Fixes Coverity CID 1396239.

Signed-off-by: Jai Luthra <me@jailuthra.in>
This commit is contained in:
Jai Luthra 2020-01-24 16:03:32 +05:30 committed by Paul B Mahol
parent 990990ed5d
commit ddeb58d58c

View File

@ -1,6 +1,7 @@
/** /**
* MLP encoder * MLP encoder
* Copyright (c) 2008 Ramiro Polla * Copyright (c) 2008 Ramiro Polla
* Copyright (c) 2016-2019 Jai Luthra
* *
* This file is part of FFmpeg. * This file is part of FFmpeg.
* *
@ -1562,7 +1563,7 @@ static void no_codebook_bits_offset(MLPEncodeContext *ctx,
BestOffset *bo) BestOffset *bo)
{ {
DecodingParams *dp = ctx->cur_decoding_params; DecodingParams *dp = ctx->cur_decoding_params;
int32_t unsign; int32_t unsign = 0;
int lsb_bits; int lsb_bits;
min -= offset; min -= offset;
@ -1572,6 +1573,7 @@ static void no_codebook_bits_offset(MLPEncodeContext *ctx,
lsb_bits += !!lsb_bits; lsb_bits += !!lsb_bits;
if (lsb_bits > 0)
unsign = 1 << (lsb_bits - 1); unsign = 1 << (lsb_bits - 1);
bo->offset = offset; bo->offset = offset;
@ -1591,7 +1593,7 @@ static void no_codebook_bits(MLPEncodeContext *ctx,
{ {
DecodingParams *dp = ctx->cur_decoding_params; DecodingParams *dp = ctx->cur_decoding_params;
int16_t offset; int16_t offset;
int32_t unsign; int32_t unsign = 0;
uint32_t diff; uint32_t diff;
int lsb_bits; int lsb_bits;
@ -1607,6 +1609,7 @@ static void no_codebook_bits(MLPEncodeContext *ctx,
lsb_bits = number_sbits(diff) - 1; lsb_bits = number_sbits(diff) - 1;
if (lsb_bits > 0)
unsign = 1 << (lsb_bits - 1); unsign = 1 << (lsb_bits - 1);
/* If all samples are the same (lsb_bits == 0), offset must be /* If all samples are the same (lsb_bits == 0), offset must be