diff mbox series

[FFmpeg-devel,15/25] avformat/utils: Don't compare pointers when sorting chapters

Message ID AM7PR03MB666075999A670A17D07F80798FC89@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit e04ddba64f4c389b33b07dba6adb89f3492b151c
Headers show
Series [FFmpeg-devel,01/25] avformat/matroskadec: Fix heap-buffer overflow upon gigantic timestamps | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/configureppc warning Failed to apply patch

Commit Message

Andreas Rheinhardt Aug. 27, 2021, 2:27 p.m. UTC
The chapters are independently allocated, so that comparing
the pointers is undefined behaviour. Furthermore, its result
is not platform-independent (and may not even be deterministic
on a particular platform). So compare the chapters' ids instead.
(avpriv_new_chapter() ensures that there are no duplicate ids.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Paul B Mahol Aug. 27, 2021, 2:29 p.m. UTC | #1
lgtm
diff mbox series

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 78bfb36cd0..264b5b1a4b 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3160,7 +3160,7 @@  static int chapter_start_cmp(const void *p1, const void *p2)
     int delta = av_compare_ts(ch1->start, ch1->time_base, ch2->start, ch2->time_base);
     if (delta)
         return delta;
-    return (ch1 > ch2) - (ch1 < ch2);
+    return FFDIFFSIGN(ch1->id, ch2->id);
 }
 
 static int compute_chapters_end(AVFormatContext *s)