apedec: fix signed integer overflows

This bit manipulation is equivalent but avoids undefined
shifts and overflows.

Signed-off-by: Mans Rullgard <mans@mansr.com>
This commit is contained in:
Mans Rullgard 2011-11-25 18:46:35 +00:00
parent 93c286e54f
commit 644bff6c9b

View File

@ -690,7 +690,7 @@ static void do_apply_filter(APEContext *ctx, int version, APEFilter *f,
/* Update the adaption coefficients */
absres = FFABS(res);
if (absres)
*f->adaptcoeffs = ((res & (1<<31)) - (1<<30)) >>
*f->adaptcoeffs = ((res & (-1<<31)) ^ (-1<<30)) >>
(25 + (absres <= f->avg*3) + (absres <= f->avg*4/3));
else
*f->adaptcoeffs = 0;