diff options
author | Ganesh Ajjanagadde <gajjanagadde@gmail.com> | 2015-11-01 18:43:56 +0300 |
---|---|---|
committer | Ganesh Ajjanagadde <gajjanagadde@gmail.com> | 2015-11-04 00:28:30 +0300 |
commit | 92e483f8ed70d88d4f64337f65bae212502735d4 (patch) | |
tree | 39934a7084b155a0034dfdb1e78248644458a33c /libavfilter/f_sendcmd.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/f_sendcmd.c')
-rw-r--r-- | libavfilter/f_sendcmd.c | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/libavfilter/f_sendcmd.c b/libavfilter/f_sendcmd.c index 37aedc59f2..fb30220e7c 100644 --- a/libavfilter/f_sendcmd.c +++ b/libavfilter/f_sendcmd.c @@ -364,11 +364,7 @@ static int cmp_intervals(const void *a, const void *b) { const Interval *i1 = a; const Interval *i2 = b; - int64_t ts_diff = i1->start_ts - i2->start_ts; - int ret; - - ret = ts_diff > 0 ? 1 : ts_diff < 0 ? -1 : 0; - return ret == 0 ? i1->index - i2->index : ret; + return 2 * FFDIFFSIGN(i1->start_ts, i2->start_ts) + FFDIFFSIGN(i1->index, i2->index); } static av_cold int init(AVFilterContext *ctx) |