From 6d5e887a20ab8102bc676223d3323e5980b2e2c8 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 19 Oct 2013 23:02:53 +0200 Subject: demux_mkv: fill ordered chapters info only if it's present This was probably not a real problem. But it's not entirely clear whether this could actually happen or not, so it's better to be defensive. The code is now also somewhat easier to understand. --- demux/demux_mkv.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'demux/demux_mkv.c') diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index ea5a22f6ee..b4eea38486 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -826,13 +826,6 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer) } else selected_edition = 0; } - struct matroska_chapter *m_chapters = NULL; - if (editions[selected_edition].edition_flag_ordered) { - int count = editions[selected_edition].n_chapter_atom; - m_chapters = talloc_array_ptrtype(demuxer, m_chapters, count); - demuxer->matroska_data.ordered_chapters = m_chapters; - demuxer->matroska_data.num_ordered_chapters = count; - } for (int idx = 0; idx < num_editions; idx++) { mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] New edition %d\n", idx); @@ -843,7 +836,17 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer) if (editions[idx].n_edition_flag_ordered) mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Ordered chapter flag: %"PRIu64 "\n", editions[idx].edition_flag_ordered); - for (int i = 0; i < editions[idx].n_chapter_atom; i++) { + + int chapter_count = editions[idx].n_chapter_atom; + + struct matroska_chapter *m_chapters = NULL; + if (idx == selected_edition && editions[idx].edition_flag_ordered) { + m_chapters = talloc_array_ptrtype(demuxer, m_chapters, chapter_count); + demuxer->matroska_data.ordered_chapters = m_chapters; + demuxer->matroska_data.num_ordered_chapters = chapter_count; + } + + for (int i = 0; i < chapter_count; i++) { struct ebml_chapter_atom *ca = editions[idx].chapter_atom + i; struct matroska_chapter chapter = { }; struct bstr name = { "(unnamed)", 9 }; @@ -899,14 +902,13 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer) (int) (chapter.end % 1000000000), BSTR_P(name)); - if (idx == selected_edition){ + if (idx == selected_edition) { demuxer_add_chapter(demuxer, name, chapter.start, chapter.end, ca->chapter_uid); - if (editions[idx].edition_flag_ordered) { - chapter.name = talloc_strndup(m_chapters, name.start, - name.len); - m_chapters[i] = chapter; - } + } + if (m_chapters) { + chapter.name = talloc_strndup(m_chapters, name.start, name.len); + m_chapters[i] = chapter; } } } -- cgit v1.2.3