From a8dc97d95dcf84397d87d26b52d429fa30f8da3e Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Tue, 4 Jul 2023 19:02:54 -0500 Subject: [PATCH] LibAudio: Don't return a seek point if it is after the desired sample If the seek table was incomplete, without any seek points available before the target point, `SeekTable::seek_point_before()` would instead return the first seek point after the target. Check whether the seek point is before the target before returning it. --- Userland/Libraries/LibAudio/GenericTypes.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Userland/Libraries/LibAudio/GenericTypes.cpp b/Userland/Libraries/LibAudio/GenericTypes.cpp index d7fdc27a2d..e40c04eb3a 100644 --- a/Userland/Libraries/LibAudio/GenericTypes.cpp +++ b/Userland/Libraries/LibAudio/GenericTypes.cpp @@ -40,6 +40,8 @@ Optional SeekTable::seek_point_before(u64 sample_index) const ++nearby_seek_point_index; while (nearby_seek_point_index > 0 && m_seek_points[nearby_seek_point_index].sample_index > sample_index) --nearby_seek_point_index; + if (m_seek_points[nearby_seek_point_index].sample_index > sample_index) + return {}; return m_seek_points[nearby_seek_point_index]; }