[FFmpeg-devel] [PATCH 1/2] avcodec/adxenc: Avoid undefined left shift of negative numbers

Michael Niedermayer michael at niedermayer.cc
Tue Jan 21 10:59:09 EET 2020


On Mon, Jan 20, 2020 at 08:20:42PM +0100, Andreas Rheinhardt wrote:
> Replace "((a << shift) + b) >> shift" by "a + (b >> shift)". This avoids
> a left shift which also happens to trigger undefined behaviour in case "a"
> is negative. This affected the FATE-tests acodec-adpcm-adx and
> acodec-adpcm-adx-trellis; it also fixes ticket #8008.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
> The equivalence of the old code and the new code in the first two
> changes is clear from the type of wav[i] (int16_t) and the fact that
> COEFF_BITS is 12 (i.e. no high bits are lost when left shifting); for
> the last change the equivalence depends upon scale being representable
> in an uint16_t. I don't know whether this is indeed so (the direct
> estimate gives an upper bound of (2^19 + 2^15 + 1) / 7), but it better
> should be so because scale is written via AV_WB16. Maybe it should be
> clipped if it is outside of this range?
> 
>  libavcodec/adxenc.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

will apply patchset

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The misfortune of the wise is better than the prosperity of the fool.
-- Epicurus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200121/90a2d110/attachment.sig>


More information about the ffmpeg-devel mailing list