From 708387b850953dd49ff0e293be2da7f8370fc0da Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Wed, 12 Apr 2023 16:15:49 +0200 Subject: [PATCH] LibAudio: Use `read_until_filled` to fill a buffer from a Stream This has the advantage of recognizing when the Stream reaches EOF and avoids an endless loop. --- Userland/Libraries/LibAudio/FlacLoader.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index 11ae35f714..4f23b7a709 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -250,12 +250,7 @@ ErrorOr FlacLoaderPlugin::next_meta_block(Big FLAC_VERIFY(!block_data_result.is_error(), LoaderError::Category::IO, "Out of memory"); auto block_data = block_data_result.release_value(); - // Blocks might exceed our buffer size. - auto bytes_left_to_read = block_data.bytes(); - while (bytes_left_to_read.size()) { - auto read_bytes = LOADER_TRY(bit_input.read_some(bytes_left_to_read)); - bytes_left_to_read = bytes_left_to_read.slice(read_bytes.size()); - } + LOADER_TRY(bit_input.read_until_filled(block_data)); m_data_start_location += block_length; return FlacRawMetadataBlock {