From b4957234af20f07c4fc15873ec0590aba17e7cf5 Mon Sep 17 00:00:00 2001 From: Johann Date: Tue, 4 Nov 2014 10:46:24 -0800 Subject: [PATCH] Avoid divide-by-zero in vp8 initialization Check that the numerator is not zero. If it is, guess 30fps. Fixes a clang IOC error in the quantize test. It's very unlikely for this to occur in the wild because the setup in the quantize test is very nonstandard. Change-Id: Icdab7b81d4e168d3423e14db20787f960052e0c3 --- vp8/encoder/onyx_if.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index 45b6b43..02b6425 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -1363,15 +1363,20 @@ static void init_config(VP8_COMP *cpi, VP8_CONFIG *oxcf) cm->version = oxcf->Version; vp8_setup_version(cm); - /* frame rate is not available on the first frame, as it's derived from + /* Frame rate is not available on the first frame, as it's derived from * the observed timestamps. The actual value used here doesn't matter - * too much, as it will adapt quickly. If the reciprocal of the timebase - * seems like a reasonable framerate, then use that as a guess, otherwise - * use 30. + * too much, as it will adapt quickly. */ - cpi->framerate = (double)(oxcf->timebase.den) / - (double)(oxcf->timebase.num); + if (oxcf->timebase.num > 0) { + cpi->framerate = (double)(oxcf->timebase.den) / + (double)(oxcf->timebase.num); + } else { + cpi->framerate = 30; + } + /* If the reciprocal of the timebase seems like a reasonable framerate, + * then use that as a guess, otherwise use 30. + */ if (cpi->framerate > 180) cpi->framerate = 30; -- 2.7.4