From 42aedd59dd650d4f8567c48ecd03eb78178a29da Mon Sep 17 00:00:00 2001 From: Oleg Oshmyan Date: Wed, 27 Aug 2014 22:24:05 +0200 Subject: process_karaoke_effects: explicitly handle edge cases for \kf In particular, don't divide by zero given \kf0. This fixes https://github.com/libass/libass/issues/124. The order is important: \kf accepts negative values. --- libass/ass_parse.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libass/ass_parse.c b/libass/ass_parse.c index 20cbff6..9ab4ab8 100644 --- a/libass/ass_parse.c +++ b/libass/ass_parse.c @@ -1008,8 +1008,14 @@ void process_karaoke_effects(ASS_Renderer *render_priv) if (effect_type == EF_KARAOKE || effect_type == EF_KARAOKE_KO) { x = tm_current < tm_start ? x_start : x_end + 1; } else if (effect_type == EF_KARAOKE_KF) { - double dt = (double) (tm_current - tm_start) / (tm_end - tm_start); - x = x_start + (x_end - x_start) * dt; + if (tm_current < tm_start) + x = x_start; + else if (tm_current >= tm_end) + x = x_end + 1; + else { + double dt = (double) (tm_current - tm_start) / (tm_end - tm_start); + x = x_start + (x_end - x_start) * dt; + } } else { ass_msg(render_priv->library, MSGL_ERR, "Unknown effect type"); -- cgit v1.2.3