Skip to content

Commit

Permalink
avutil/integer: Fix av_mod_i() with negative dividend
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Niedermayer <[email protected]>
  • Loading branch information
michaelni committed Dec 1, 2015
1 parent 8e7f452 commit 3a9cb18
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libavutil/integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "integer.h"
#include "avassert.h"

static const AVInteger zero_i;

AVInteger av_add_i(AVInteger a, AVInteger b){
int i, carry=0;

Expand Down Expand Up @@ -111,6 +113,12 @@ AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){
AVInteger quot_temp;
if(!quot) quot = &quot_temp;

if ((int16_t)a.v[AV_INTEGER_SIZE-1] < 0) {
a = av_mod_i(quot, av_sub_i(zero_i, a), b);
*quot = av_sub_i(zero_i, *quot);
return av_sub_i(zero_i, a);
}

av_assert2((int16_t)a.v[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b.v[AV_INTEGER_SIZE-1] >= 0);
av_assert2(av_log2_i(b)>=0);

Expand Down

0 comments on commit 3a9cb18

Please sign in to comment.