1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-28 01:52:19 +00:00

mplayer: don't display "-1" as chapter when chapter seek fails

Increase robustness against out of bound chapter numbers. Normally
these functions expect that the callers sanitize the chapter number.
This went wrong at least in add_seek_osd_messages() (which displayed
a chapter "-1" when chapters were not available). Make these functions
a bit friendler and add some reasonable checks and fallbacks, which
fixes the mentioned chapter seeking case as well.
This commit is contained in:
wm4 2013-02-19 23:56:39 +01:00
parent 145c965135
commit bad027277c

View File

@ -3028,6 +3028,8 @@ char *chapter_display_name(struct MPContext *mpctx, int chapter)
char *dname = name;
if (name) {
dname = talloc_asprintf(NULL, "(%d) %s", chapter + 1, name);
} else if (chapter < -1) {
dname = talloc_strdup(NULL, "(unavailable)");
} else {
int chapter_count = get_chapter_count(mpctx);
if (chapter_count <= 0)
@ -3044,8 +3046,11 @@ char *chapter_display_name(struct MPContext *mpctx, int chapter)
// returns NULL if chapter name unavailable
char *chapter_name(struct MPContext *mpctx, int chapter)
{
if (mpctx->chapters)
if (mpctx->chapters) {
if (chapter < 0 || chapter >= mpctx->num_chapters)
return NULL;
return talloc_strdup(NULL, mpctx->chapters[chapter].name);
}
if (mpctx->master_demuxer)
return demuxer_chapter_name(mpctx->master_demuxer, chapter);
return NULL;