From bad027277c8106e1f0176d801d6752a4b18df8e6 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 19 Feb 2013 23:56:39 +0100 Subject: 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. --- core/mplayer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/mplayer.c b/core/mplayer.c index 7a80701c16..f442fa24a8 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -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; -- cgit v1.2.3