summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-02-19 23:56:39 +0100
committerwm4 <wm4@nowhere>2013-02-20 00:54:18 +0100
commitbad027277c8106e1f0176d801d6752a4b18df8e6 (patch)
tree9ff73f1438d2bae480884fe1cf2897b438eda1f2 /core
parent145c965135dc01869051173007257123df7f0a4b (diff)
downloadmpv-bad027277c8106e1f0176d801d6752a4b18df8e6.tar.bz2
mpv-bad027277c8106e1f0176d801d6752a4b18df8e6.tar.xz
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.
Diffstat (limited to 'core')
-rw-r--r--core/mplayer.c7
1 files changed, 6 insertions, 1 deletions
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;