summaryrefslogtreecommitdiffstats
path: root/video/out
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.xyz>2017-09-11 02:07:04 +0200
committerNiklas Haas <git@haasn.xyz>2017-09-11 02:07:04 +0200
commit8a4f2f0ac001703f0fcb921067d97584df20e2fc (patch)
tree4ddba26c45c40fe3ab70a7c43696d96c509e4eb4 /video/out
parent0fe4a492c431610dc69b66eb4397707bda178b99 (diff)
downloadmpv-8a4f2f0ac001703f0fcb921067d97584df20e2fc.tar.bz2
mpv-8a4f2f0ac001703f0fcb921067d97584df20e2fc.tar.xz
vo_opengl: fix out-of-bounds access in timer_pool_measure
This was there even before the refactor, but the refactor exposed the bug. I hate C's useless fucking modulo operator so much. I've gotten hit by this exact bug way too many times.
Diffstat (limited to 'video/out')
-rw-r--r--video/out/opengl/utils.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/video/out/opengl/utils.c b/video/out/opengl/utils.c
index 13f183f7a0..e71c01de04 100644
--- a/video/out/opengl/utils.c
+++ b/video/out/opengl/utils.c
@@ -293,8 +293,9 @@ struct mp_pass_perf timer_pool_measure(struct timer_pool *pool)
if (!pool)
return (struct mp_pass_perf){0};
+ int last = (pool->sample_idx ? pool->sample_idx : VO_PERF_SAMPLE_COUNT) - 1;
struct mp_pass_perf res = {
- .last = pool->samples[(pool->sample_idx - 1) % VO_PERF_SAMPLE_COUNT],
+ .last = pool->samples[last],
.avg = pool->sample_count > 0 ? pool->sum / pool->sample_count : 0,
.peak = pool->peak,
.count = pool->sample_count,