1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:47:46 +00:00

LibAudio: Use ReadonlyBytes instead of Bytes for buffer parameters

Bytes will implicitly cast to StringView, but not to ReadonlyBytes. That
means that if you call
`Audio::Loader::create_plugin(mapped_file->bytes())`
it will silently use the `create_plugin(StringView path)` overload.

Reading audio data does not require that data to be writable, so let's
use ReadonlyBytes for it and avoid the footgun.
This commit is contained in:
Sam Atkins 2023-06-27 12:04:29 +01:00 committed by Sam Atkins
parent 8e0fa57e5b
commit 0a9fa85e86
4 changed files with 5 additions and 4 deletions

View file

@ -47,7 +47,8 @@ ErrorOr<NonnullRefPtr<Loader>, LoaderError> Loader::create(StringView path)
auto stream = TRY(Core::InputBufferedFile::create(TRY(Core::File::open(path, Core::File::OpenMode::Read))));
return adopt_ref(*new (nothrow) Loader(TRY(Loader::create_plugin(move(stream)))));
}
ErrorOr<NonnullRefPtr<Loader>, LoaderError> Loader::create(Bytes buffer)
ErrorOr<NonnullRefPtr<Loader>, LoaderError> Loader::create(ReadonlyBytes buffer)
{
auto stream = TRY(try_make<FixedMemoryStream>(buffer));
return adopt_ref(*new (nothrow) Loader(TRY(Loader::create_plugin(move(stream)))));