diff options
author | Ganesh Ajjanagadde <gajjanagadde@gmail.com> | 2015-11-01 10:43:56 -0500 |
---|---|---|
committer | Ganesh Ajjanagadde <gajjanagadde@gmail.com> | 2015-11-03 16:28:30 -0500 |
commit | 92e483f8ed70d88d4f64337f65bae212502735d4 (patch) | |
tree | 39934a7084b155a0034dfdb1e78248644458a33c /libavfilter/vf_removegrain.c | |
parent | 265f83fd35977a80e93b3cc13ceb65f52f129a3c (diff) |
all: use FFDIFFSIGN to resolve possible undefined behavior in comparators
FFDIFFSIGN was created explicitly for this purpose, since the common
return a - b idiom is unsafe regarding overflow on signed integers. It
optimizes to branchless code on common compilers.
FFDIFFSIGN also has the subjective benefit of being easier to read due
to lack of ternary operators.
Tested with FATE.
Things not covered by this are unsigned integers, for which overflows
are well defined, and also places where overflow is clearly impossible,
e.g an instance where the a - b was being done on 24 bit values.
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Reviewed-by: Clément Bœsch <u@pkh.me>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
Diffstat (limited to 'libavfilter/vf_removegrain.c')
-rw-r--r-- | libavfilter/vf_removegrain.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/libavfilter/vf_removegrain.c b/libavfilter/vf_removegrain.c index 3a28b15cdb..898e50f101 100644 --- a/libavfilter/vf_removegrain.c +++ b/libavfilter/vf_removegrain.c @@ -83,10 +83,9 @@ static int mode01(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, static int cmp_int(const void *p1, const void *p2) { - int left = *(const int *)p1; + int left = *(const int *)p1; int right = *(const int *)p2; - - return ((left > right) - (left < right)); + return FFDIFFSIGN(left, right); } static int mode02(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) |