diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2015-12-01 12:41:43 +0100 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2015-12-14 16:51:00 +0100 |
commit | 07a30246315b568fc2155e17a4e78529082657ed (patch) | |
tree | e2726ec86ac01f706c028a5a24f1e3cf640c4ed0 | |
parent | cf1f615b67a4a486176b9aeaedeceef0337023e9 (diff) | |
download | ffmpeg-07a30246315b568fc2155e17a4e78529082657ed.tar.gz |
avutil/integer: Fix av_mod_i() with negative dividend
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 3a9cb18855d29c96a5d9d2f5ad30448cae3a2ddf)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libavutil/integer.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libavutil/integer.c b/libavutil/integer.c index 5bcde0dc6e..6d6855fa1b 100644 --- a/libavutil/integer.c +++ b/libavutil/integer.c @@ -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; @@ -111,6 +113,12 @@ AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){ AVInteger quot_temp; if(!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); |