summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AK/MemoryStream.cpp10
-rw-r--r--AK/MemoryStream.h7
-rw-r--r--Meta/Lagom/Fuzzers/FuzzBrotli.cpp9
-rw-r--r--Meta/Lagom/Fuzzers/FuzzTar.cpp2
-rw-r--r--Meta/Lagom/Fuzzers/FuzzWasmParser.cpp7
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp8
-rw-r--r--Tests/AK/TestLEB128.cpp100
-rw-r--r--Tests/LibCompress/TestDeflate.cpp4
-rw-r--r--Tests/LibWasm/test-wasm.cpp4
-rw-r--r--Userland/Libraries/LibAudio/FlacLoader.cpp26
-rw-r--r--Userland/Libraries/LibAudio/MP3Loader.cpp2
-rw-r--r--Userland/Libraries/LibAudio/WavLoader.cpp14
-rw-r--r--Userland/Libraries/LibCompress/Deflate.cpp2
-rw-r--r--Userland/Libraries/LibCompress/Gzip.cpp2
-rw-r--r--Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp18
-rw-r--r--Userland/Libraries/LibDebug/Dwarf/AddressRanges.h1
-rw-r--r--Userland/Libraries/LibDebug/Dwarf/DIE.cpp18
-rw-r--r--Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp22
-rw-r--r--Userland/Libraries/LibDebug/Dwarf/Expression.cpp6
-rw-r--r--Userland/Libraries/LibGfx/GIFLoader.cpp60
-rw-r--r--Userland/Libraries/LibGfx/ICOLoader.cpp16
-rw-r--r--Userland/Libraries/LibGfx/JPGLoader.cpp2
-rw-r--r--Userland/Libraries/LibGfx/QOILoader.cpp6
-rw-r--r--Userland/Libraries/LibHTTP/Job.cpp4
-rw-r--r--Userland/Libraries/LibPDF/DocumentParser.cpp2
-rw-r--r--Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp20
-rw-r--r--Userland/Libraries/LibWasm/Parser/Parser.cpp4
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp4
-rw-r--r--Userland/Services/WebServer/Client.cpp4
-rw-r--r--Userland/Utilities/headless-browser.cpp6
-rw-r--r--Userland/Utilities/wasm.cpp4
31 files changed, 185 insertions, 209 deletions
diff --git a/AK/MemoryStream.cpp b/AK/MemoryStream.cpp
index d4c9659b3a..10c35f0bf0 100644
--- a/AK/MemoryStream.cpp
+++ b/AK/MemoryStream.cpp
@@ -23,16 +23,6 @@ FixedMemoryStream::FixedMemoryStream(ReadonlyBytes bytes)
{
}
-ErrorOr<NonnullOwnPtr<FixedMemoryStream>> FixedMemoryStream::construct(Bytes bytes)
-{
- return adopt_nonnull_own_or_enomem<FixedMemoryStream>(new (nothrow) FixedMemoryStream(bytes));
-}
-
-ErrorOr<NonnullOwnPtr<FixedMemoryStream>> FixedMemoryStream::construct(ReadonlyBytes bytes)
-{
- return adopt_nonnull_own_or_enomem<FixedMemoryStream>(new (nothrow) FixedMemoryStream(bytes));
-}
-
bool FixedMemoryStream::is_eof() const
{
return m_offset >= m_bytes.size();
diff --git a/AK/MemoryStream.h b/AK/MemoryStream.h
index b81310b063..fa4961b77b 100644
--- a/AK/MemoryStream.h
+++ b/AK/MemoryStream.h
@@ -16,8 +16,8 @@ namespace AK {
/// using a single read/write head.
class FixedMemoryStream final : public SeekableStream {
public:
- static ErrorOr<NonnullOwnPtr<FixedMemoryStream>> construct(Bytes bytes);
- static ErrorOr<NonnullOwnPtr<FixedMemoryStream>> construct(ReadonlyBytes bytes);
+ explicit FixedMemoryStream(Bytes bytes);
+ explicit FixedMemoryStream(ReadonlyBytes bytes);
virtual bool is_eof() const override;
virtual bool is_open() const override;
@@ -36,9 +36,6 @@ public:
size_t remaining() const;
private:
- explicit FixedMemoryStream(Bytes bytes);
- explicit FixedMemoryStream(ReadonlyBytes bytes);
-
Bytes m_bytes;
size_t m_offset { 0 };
bool m_writing_enabled { true };
diff --git a/Meta/Lagom/Fuzzers/FuzzBrotli.cpp b/Meta/Lagom/Fuzzers/FuzzBrotli.cpp
index e3dbbf1be4..db75f5c3fd 100644
--- a/Meta/Lagom/Fuzzers/FuzzBrotli.cpp
+++ b/Meta/Lagom/Fuzzers/FuzzBrotli.cpp
@@ -10,14 +10,9 @@
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
- auto bufstream_result = FixedMemoryStream::construct({ data, size });
- if (bufstream_result.is_error()) {
- dbgln("MemoryStream::construct() failed.");
- return 0;
- }
- auto bufstream = bufstream_result.release_value();
+ FixedMemoryStream bufstream { { data, size } };
- auto brotli_stream = Compress::BrotliDecompressionStream { *bufstream };
+ auto brotli_stream = Compress::BrotliDecompressionStream { bufstream };
(void)brotli_stream.read_until_eof();
return 0;
diff --git a/Meta/Lagom/Fuzzers/FuzzTar.cpp b/Meta/Lagom/Fuzzers/FuzzTar.cpp
index 50be8ec74f..88c81139dd 100644
--- a/Meta/Lagom/Fuzzers/FuzzTar.cpp
+++ b/Meta/Lagom/Fuzzers/FuzzTar.cpp
@@ -12,7 +12,7 @@
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
- auto input_stream_or_error = FixedMemoryStream::construct({ data, size });
+ auto input_stream_or_error = try_make<FixedMemoryStream>(ReadonlyBytes { data, size });
if (input_stream_or_error.is_error())
return 0;
diff --git a/Meta/Lagom/Fuzzers/FuzzWasmParser.cpp b/Meta/Lagom/Fuzzers/FuzzWasmParser.cpp
index aaa4dfabca..7a677dd6d5 100644
--- a/Meta/Lagom/Fuzzers/FuzzWasmParser.cpp
+++ b/Meta/Lagom/Fuzzers/FuzzWasmParser.cpp
@@ -12,10 +12,7 @@
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
ReadonlyBytes bytes { data, size };
- auto stream_or_error = FixedMemoryStream::construct(bytes);
- if (stream_or_error.is_error())
- return 0;
- auto stream = stream_or_error.release_value();
- [[maybe_unused]] auto result = Wasm::Module::parse(*stream);
+ FixedMemoryStream stream { bytes };
+ [[maybe_unused]] auto result = Wasm::Module::parse(stream);
return 0;
}
diff --git a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp
index 9dc65385af..9d58aa0ff3 100644
--- a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp
@@ -586,8 +586,8 @@ public:
static ErrorOr<NonnullOwnPtr<IPC::Message>> decode_message(ReadonlyBytes buffer, [[maybe_unused]] Core::Stream::LocalSocket& socket)
{
- auto stream = TRY(FixedMemoryStream::construct(buffer));
- auto message_endpoint_magic = TRY(stream->read_value<u32>());)~~~");
+ FixedMemoryStream stream { buffer };
+ auto message_endpoint_magic = TRY(stream.read_value<u32>());)~~~");
generator.append(R"~~~(
if (message_endpoint_magic != @endpoint.magic@) {)~~~");
@@ -599,7 +599,7 @@ public:
return Error::from_string_literal("Endpoint magic number mismatch, not my message!");
}
- auto message_id = TRY(stream->read_value<i32>());)~~~");
+ auto message_id = TRY(stream.read_value<i32>());)~~~");
generator.appendln(R"~~~(
switch (message_id) {)~~~");
@@ -613,7 +613,7 @@ public:
message_generator.append(R"~~~(
case (int)Messages::@endpoint.name@::MessageID::@message.pascal_name@:
- return TRY(Messages::@endpoint.name@::@message.pascal_name@::decode(*stream, socket));)~~~");
+ return TRY(Messages::@endpoint.name@::@message.pascal_name@::decode(stream, socket));)~~~");
};
do_decode_message(message.name);
diff --git a/Tests/AK/TestLEB128.cpp b/Tests/AK/TestLEB128.cpp
index 1e7c68024e..996a3cbb9a 100644
--- a/Tests/AK/TestLEB128.cpp
+++ b/Tests/AK/TestLEB128.cpp
@@ -14,18 +14,18 @@ TEST_CASE(single_byte)
u32 output = {};
i32 output_signed = {};
u8 buf[] = { 0x00 };
- auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { buf, sizeof(buf) }));
+ FixedMemoryStream stream { ReadonlyBytes { buf, sizeof(buf) } };
// less than/eq 0b0011_1111, signed == unsigned == raw byte
for (u8 i = 0u; i <= 0x3F; ++i) {
buf[0] = i;
- MUST(stream->seek(0));
- output = MUST(stream->read_value<LEB128<u32>>());
+ MUST(stream.seek(0));
+ output = MUST(stream.read_value<LEB128<u32>>());
EXPECT_EQ(output, i);
- MUST(stream->seek(0));
- output_signed = MUST(stream->read_value<LEB128<i32>>());
+ MUST(stream.seek(0));
+ output_signed = MUST(stream.read_value<LEB128<i32>>());
EXPECT_EQ(output_signed, i);
}
@@ -33,23 +33,23 @@ TEST_CASE(single_byte)
for (u8 i = 0x40u; i < 0x80; ++i) {
buf[0] = i;
- MUST(stream->seek(0));
- output = MUST(stream->read_value<LEB128<u32>>());
+ MUST(stream.seek(0));
+ output = MUST(stream.read_value<LEB128<u32>>());
EXPECT_EQ(output, i);
- MUST(stream->seek(0));
- output_signed = MUST(stream->read_value<LEB128<i32>>());
+ MUST(stream.seek(0));
+ output_signed = MUST(stream.read_value<LEB128<i32>>());
EXPECT_EQ(output_signed, (i | (-1 & (~0x3F))));
}
// MSB set, but input too short
for (u16 i = 0x80; i <= 0xFF; ++i) {
buf[0] = static_cast<u8>(i);
- MUST(stream->seek(0));
- EXPECT(stream->read_value<LEB128<u32>>().is_error());
+ MUST(stream.seek(0));
+ EXPECT(stream.read_value<LEB128<u32>>().is_error());
- MUST(stream->seek(0));
- EXPECT(stream->read_value<LEB128<i32>>().is_error());
+ MUST(stream.seek(0));
+ EXPECT(stream.read_value<LEB128<i32>>().is_error());
}
}
@@ -58,7 +58,7 @@ TEST_CASE(two_bytes)
u32 output = {};
i32 output_signed = {};
u8 buf[] = { 0x00, 0x1 };
- auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { buf, sizeof(buf) }));
+ FixedMemoryStream stream { ReadonlyBytes { buf, sizeof(buf) } };
// Only test with first byte expecting more, otherwise equivalent to single byte case
for (u16 i = 0x80; i <= 0xFF; ++i) {
@@ -68,12 +68,12 @@ TEST_CASE(two_bytes)
for (u8 j = 0u; j <= 0x3F; ++j) {
buf[1] = j;
- MUST(stream->seek(0));
- output = MUST(stream->read_value<LEB128<u32>>());
+ MUST(stream.seek(0));
+ output = MUST(stream.read_value<LEB128<u32>>());
EXPECT_EQ(output, (static_cast<u32>(j) << 7) + (i & 0x7F));
- MUST(stream->seek(0));
- output_signed = MUST(stream->read_value<LEB128<i32>>());
+ MUST(stream.seek(0));
+ output_signed = MUST(stream.read_value<LEB128<i32>>());
EXPECT_EQ(output_signed, (static_cast<i32>(j) << 7) + (i & 0x7F));
}
@@ -81,12 +81,12 @@ TEST_CASE(two_bytes)
for (u8 j = 0x40u; j < 0x80; ++j) {
buf[1] = j;
- MUST(stream->seek(0));
- output = MUST(stream->read_value<LEB128<u32>>());
+ MUST(stream.seek(0));
+ output = MUST(stream.read_value<LEB128<u32>>());
EXPECT_EQ(output, (static_cast<u32>(j) << 7) + (i & 0x7F));
- MUST(stream->seek(0));
- output_signed = MUST(stream->read_value<LEB128<i32>>());
+ MUST(stream.seek(0));
+ output_signed = MUST(stream.read_value<LEB128<i32>>());
EXPECT_EQ(output_signed, ((static_cast<i32>(j) << 7) + (i & 0x7F)) | (-1 & (~0x3FFF)));
}
@@ -94,11 +94,11 @@ TEST_CASE(two_bytes)
for (u16 j = 0x80; j <= 0xFF; ++j) {
buf[1] = static_cast<u8>(j);
- MUST(stream->seek(0));
- EXPECT(stream->read_value<LEB128<u32>>().is_error());
+ MUST(stream.seek(0));
+ EXPECT(stream.read_value<LEB128<u32>>().is_error());
- MUST(stream->seek(0));
- EXPECT(stream->read_value<LEB128<i32>>().is_error());
+ MUST(stream.seek(0));
+ EXPECT(stream.read_value<LEB128<i32>>().is_error());
}
}
}
@@ -107,22 +107,22 @@ TEST_CASE(overflow_sizeof_output_unsigned)
{
u8 u32_max_plus_one[] = { 0x80, 0x80, 0x80, 0x80, 0x10 };
{
- auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { u32_max_plus_one, sizeof(u32_max_plus_one) }));
- EXPECT(stream->read_value<LEB128<u32>>().is_error());
+ FixedMemoryStream stream { ReadonlyBytes { u32_max_plus_one, sizeof(u32_max_plus_one) } };
+ EXPECT(stream.read_value<LEB128<u32>>().is_error());
- MUST(stream->seek(0));
- u64 out64 = MUST(stream->read_value<LEB128<u64>>());
+ MUST(stream.seek(0));
+ u64 out64 = MUST(stream.read_value<LEB128<u64>>());
EXPECT_EQ(out64, static_cast<u64>(NumericLimits<u32>::max()) + 1);
}
u8 u32_max[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x0F };
{
- auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { u32_max, sizeof(u32_max) }));
- u32 out = MUST(stream->read_value<LEB128<u32>>());
+ FixedMemoryStream stream { ReadonlyBytes { u32_max, sizeof(u32_max) } };
+ u32 out = MUST(stream.read_value<LEB128<u32>>());
EXPECT_EQ(out, NumericLimits<u32>::max());
- MUST(stream->seek(0));
- u64 out64 = MUST(stream->read_value<LEB128<u64>>());
+ MUST(stream.seek(0));
+ u64 out64 = MUST(stream.read_value<LEB128<u64>>());
EXPECT_EQ(out64, NumericLimits<u32>::max());
}
}
@@ -131,43 +131,43 @@ TEST_CASE(overflow_sizeof_output_signed)
{
u8 i32_max_plus_one[] = { 0x80, 0x80, 0x80, 0x80, 0x08 };
{
- auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { i32_max_plus_one, sizeof(i32_max_plus_one) }));
- EXPECT(stream->read_value<LEB128<i32>>().is_error());
+ FixedMemoryStream stream { ReadonlyBytes { i32_max_plus_one, sizeof(i32_max_plus_one) } };
+ EXPECT(stream.read_value<LEB128<i32>>().is_error());
- MUST(stream->seek(0));
- i64 out64 = MUST(stream->read_value<LEB128<i64>>());
+ MUST(stream.seek(0));
+ i64 out64 = MUST(stream.read_value<LEB128<i64>>());
EXPECT_EQ(out64, static_cast<i64>(NumericLimits<i32>::max()) + 1);
}
u8 i32_max[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x07 };
{
- auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { i32_max, sizeof(i32_max) }));
- i32 out = MUST(stream->read_value<LEB128<i32>>());
+ FixedMemoryStream stream { ReadonlyBytes { i32_max, sizeof(i32_max) } };
+ i32 out = MUST(stream.read_value<LEB128<i32>>());
EXPECT_EQ(out, NumericLimits<i32>::max());
- MUST(stream->seek(0));
- i64 out64 = MUST(stream->read_value<LEB128<i64>>());
+ MUST(stream.seek(0));
+ i64 out64 = MUST(stream.read_value<LEB128<i64>>());
EXPECT_EQ(out64, NumericLimits<i32>::max());
}
u8 i32_min_minus_one[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x77 };
{
- auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { i32_min_minus_one, sizeof(i32_min_minus_one) }));
- EXPECT(stream->read_value<LEB128<i32>>().is_error());
+ FixedMemoryStream stream { ReadonlyBytes { i32_min_minus_one, sizeof(i32_min_minus_one) } };
+ EXPECT(stream.read_value<LEB128<i32>>().is_error());
- MUST(stream->seek(0));
- i64 out64 = MUST(stream->read_value<LEB128<i64>>());
+ MUST(stream.seek(0));
+ i64 out64 = MUST(stream.read_value<LEB128<i64>>());
EXPECT_EQ(out64, static_cast<i64>(NumericLimits<i32>::min()) - 1);
}
u8 i32_min[] = { 0x80, 0x80, 0x80, 0x80, 0x78 };
{
- auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { i32_min, sizeof(i32_min) }));
- i32 out = MUST(stream->read_value<LEB128<i32>>());
+ FixedMemoryStream stream { ReadonlyBytes { i32_min, sizeof(i32_min) } };
+ i32 out = MUST(stream.read_value<LEB128<i32>>());
EXPECT_EQ(out, NumericLimits<i32>::min());
- MUST(stream->seek(0));
- i64 out64 = MUST(stream->read_value<LEB128<i64>>());
+ MUST(stream.seek(0));
+ i64 out64 = MUST(stream.read_value<LEB128<i64>>());
EXPECT_EQ(out64, NumericLimits<i32>::min());
}
}
diff --git a/Tests/LibCompress/TestDeflate.cpp b/Tests/LibCompress/TestDeflate.cpp
index 8e50430d22..e51092e5b3 100644
--- a/Tests/LibCompress/TestDeflate.cpp
+++ b/Tests/LibCompress/TestDeflate.cpp
@@ -28,7 +28,7 @@ TEST_CASE(canonical_code_simple)
};
auto const huffman = Compress::CanonicalCode::from_bytes(code).value();
- auto memory_stream = MUST(FixedMemoryStream::construct(input));
+ auto memory_stream = MUST(try_make<FixedMemoryStream>(input));
LittleEndianInputBitStream bit_stream { move(memory_stream) };
for (size_t idx = 0; idx < 9; ++idx)
@@ -48,7 +48,7 @@ TEST_CASE(canonical_code_complex)
};
auto const huffman = Compress::CanonicalCode::from_bytes(code).value();
- auto memory_stream = MUST(FixedMemoryStream::construct(input));
+ auto memory_stream = MUST(try_make<FixedMemoryStream>(input));
LittleEndianInputBitStream bit_stream { move(memory_stream) };
for (size_t idx = 0; idx < 12; ++idx)
diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp
index 917d32b94c..1cbeff367a 100644
--- a/Tests/LibWasm/test-wasm.cpp
+++ b/Tests/LibWasm/test-wasm.cpp
@@ -106,8 +106,8 @@ TESTJS_GLOBAL_FUNCTION(parse_webassembly_module, parseWebAssemblyModule)
if (!is<JS::Uint8Array>(object))
return vm.throw_completion<JS::TypeError>("Expected a Uint8Array argument to parse_webassembly_module");
auto& array = static_cast<JS::Uint8Array&>(*object);
- auto stream = FixedMemoryStream::construct(array.data()).release_value_but_fixme_should_propagate_errors();
- auto result = Wasm::Module::parse(*stream);
+ FixedMemoryStream stream { array.data() };
+ auto result = Wasm::Module::parse(stream);
if (result.is_error())
return vm.throw_completion<JS::SyntaxError>(Wasm::parse_error_to_deprecated_string(result.error()));
diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp
index d2ba2ed2cb..26036610d4 100644
--- a/Userland/Libraries/LibAudio/FlacLoader.cpp
+++ b/Userland/Libraries/LibAudio/FlacLoader.cpp
@@ -42,7 +42,7 @@ Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> FlacLoaderPlugin::create(St
Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> FlacLoaderPlugin::create(Bytes buffer)
{
- auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer));
+ auto stream = LOADER_TRY(try_make<FixedMemoryStream>(buffer));
auto loader = make<FlacLoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
@@ -78,8 +78,8 @@ MaybeLoaderError FlacLoaderPlugin::parse_header()
// Receive the streaminfo block
auto streaminfo = TRY(next_meta_block(bit_input));
FLAC_VERIFY(streaminfo.type == FlacMetadataBlockType::STREAMINFO, LoaderError::Category::Format, "First block must be STREAMINFO");
- auto streaminfo_data_memory = LOADER_TRY(FixedMemoryStream::construct(streaminfo.data.bytes()));
- BigEndianInputBitStream streaminfo_data { MaybeOwned<AK::Stream>(*streaminfo_data_memory) };
+ FixedMemoryStream streaminfo_data_memory { streaminfo.data.bytes() };
+ BigEndianInputBitStream streaminfo_data { MaybeOwned<AK::Stream>(streaminfo_data_memory) };
// 11.10 METADATA_BLOCK_STREAMINFO
m_min_block_size = LOADER_TRY(streaminfo_data.read_bits<u16>(16));
@@ -149,8 +149,8 @@ MaybeLoaderError FlacLoaderPlugin::parse_header()
// 11.19. METADATA_BLOCK_PICTURE
MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block)
{
- auto memory_stream = LOADER_TRY(FixedMemoryStream::construct(block.data.bytes()));
- BigEndianInputBitStream picture_block_bytes { MaybeOwned<AK::Stream>(*memory_stream) };
+ FixedMemoryStream memory_stream { block.data.bytes() };
+ BigEndianInputBitStream picture_block_bytes { MaybeOwned<AK::Stream>(memory_stream) };
PictureData picture {};
@@ -158,13 +158,13 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block)
auto const mime_string_length = LOADER_TRY(picture_block_bytes.read_bits(32));
// Note: We are seeking before reading the value to ensure that we stayed inside buffer's size.
- auto offset_before_seeking = memory_stream->offset();
- LOADER_TRY(memory_stream->seek(mime_string_length, SeekMode::FromCurrentPosition));
+ auto offset_before_seeking = memory_stream.offset();
+ LOADER_TRY(memory_stream.seek(mime_string_length, SeekMode::FromCurrentPosition));
picture.mime_string = { block.data.bytes().data() + offset_before_seeking, (size_t)mime_string_length };
auto const description_string_length = LOADER_TRY(picture_block_bytes.read_bits(32));
- offset_before_seeking = memory_stream->offset();
- LOADER_TRY(memory_stream->seek(description_string_length, SeekMode::FromCurrentPosition));
+ offset_before_seeking = memory_stream.offset();
+ LOADER_TRY(memory_stream.seek(description_string_length, SeekMode::FromCurrentPosition));
picture.description_string = Vector<u32> { Span<u32> { reinterpret_cast<u32*>(block.data.bytes().data() + offset_before_seeking), (size_t)description_string_length } };
picture.width = LOADER_TRY(picture_block_bytes.read_bits(32));
@@ -174,8 +174,8 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block)
picture.colors = LOADER_TRY(picture_block_bytes.read_bits(32));
auto const picture_size = LOADER_TRY(picture_block_bytes.read_bits(32));
- offset_before_seeking = memory_stream->offset();
- LOADER_TRY(memory_stream->seek(picture_size, SeekMode::FromCurrentPosition));
+ offset_before_seeking = memory_stream.offset();
+ LOADER_TRY(memory_stream.seek(picture_size, SeekMode::FromCurrentPosition));
picture.data = Vector<u8> { Span<u8> { block.data.bytes().data() + offset_before_seeking, (size_t)picture_size } };
m_pictures.append(move(picture));
@@ -186,8 +186,8 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block)
// 11.13. METADATA_BLOCK_SEEKTABLE
MaybeLoaderError FlacLoaderPlugin::load_seektable(FlacRawMetadataBlock& block)
{
- auto memory_stream = LOADER_TRY(FixedMemoryStream::construct(block.data.bytes()));
- BigEndianInputBitStream seektable_bytes { MaybeOwned<AK::Stream>(*memory_stream) };
+ FixedMemoryStream memory_stream { block.data.bytes() };
+ BigEndianInputBitStream seektable_bytes { MaybeOwned<AK::Stream>(memory_stream) };
for (size_t i = 0; i < block.length / 18; ++i) {
// 11.14. SEEKPOINT
FlacSeekPoint seekpoint {
diff --git a/Userland/Libraries/LibAudio/MP3Loader.cpp b/Userland/Libraries/LibAudio/MP3Loader.cpp
index 693f680527..59a90cf233 100644
--- a/Userland/Libraries/LibAudio/MP3Loader.cpp
+++ b/Userland/Libraries/LibAudio/MP3Loader.cpp
@@ -31,7 +31,7 @@ Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> MP3LoaderPlugin::create(Stri
Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> MP3LoaderPlugin::create(Bytes buffer)
{
- auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer));
+ auto stream = LOADER_TRY(try_make<FixedMemoryStream>(buffer));
auto loader = make<MP3LoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
diff --git a/Userland/Libraries/LibAudio/WavLoader.cpp b/Userland/Libraries/LibAudio/WavLoader.cpp
index 4fcff2ae88..f222cd4cfc 100644
--- a/Userland/Libraries/LibAudio/WavLoader.cpp
+++ b/Userland/Libraries/LibAudio/WavLoader.cpp
@@ -35,7 +35,7 @@ Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> WavLoaderPlugin::create(Stri
Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> WavLoaderPlugin::create(Bytes buffer)
{
- auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer));
+ auto stream = LOADER_TRY(try_make<FixedMemoryStream>(buffer));
auto loader = make<WavLoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
@@ -115,23 +115,23 @@ static ErrorOr<double> read_sample(AK::Stream& stream)
LoaderSamples WavLoaderPlugin::samples_from_pcm_data(Bytes const& data, size_t samples_to_read) const
{
FixedArray<Sample> samples = LOADER_TRY(FixedArray<Sample>::create(samples_to_read));
- auto stream = LOADER_TRY(FixedMemoryStream::construct(move(data)));
+ FixedMemoryStream stream { data };
switch (m_sample_format) {
case PcmSampleFormat::Uint8:
- TRY(read_samples_from_stream(*stream, read_sample<u8>, samples));
+ TRY(read_samples_from_stream(stream, read_sample<u8>, samples));
break;
case PcmSampleFormat::Int16:
- TRY(read_samples_from_stream(*stream, read_sample<i16>, samples));
+ TRY(read_samples_from_stream(stream, read_sample<i16>, samples));
break;
case PcmSampleFormat::Int24:
- TRY(read_samples_from_stream(*stream, read_sample_int24, samples));
+ TRY(read_samples_from_stream(stream, read_sample_int24, samples));
break;
case PcmSampleFormat::Float32:
- TRY(read_samples_from_stream(*stream, read_sample<float>, samples));
+ TRY(read_samples_from_stream(stream, read_sample<float>, samples));
break;
case PcmSampleFormat::Float64:
- TRY(read_samples_from_stream(*stream, read_sample<double>, samples));
+ TRY(read_samples_from_stream(stream, read_sample<double>, samples));
break;
default:
VERIFY_NOT_REACHED();
diff --git a/Userland/Libraries/LibCompress/Deflate.cpp b/Userland/Libraries/LibCompress/Deflate.cpp
index f6c296635f..0dc24c55a1 100644
--- a/Userland/Libraries/LibCompress/Deflate.cpp
+++ b/Userland/Libraries/LibCompress/Deflate.cpp
@@ -317,7 +317,7 @@ void DeflateDecompressor::close()
ErrorOr<ByteBuffer> DeflateDecompressor::decompress_all(ReadonlyBytes bytes)
{
- auto memory_stream = TRY(FixedMemoryStream::construct(bytes));
+ auto memory_stream = TRY(try_make<FixedMemoryStream>(bytes));
auto deflate_stream = TRY(DeflateDecompressor::construct(move(memory_stream)));
AllocatingMemoryStream output_stream;
diff --git a/Userland/Libraries/LibCompress/Gzip.cpp b/Userland/Libraries/LibCompress/Gzip.cpp
index 93208319d4..3fcb2adb22 100644
--- a/Userland/Libraries/LibCompress/Gzip.cpp
+++ b/Userland/Libraries/LibCompress/Gzip.cpp
@@ -164,7 +164,7 @@ Optional<DeprecatedString> GzipDecompressor::describe_header(ReadonlyBytes bytes
ErrorOr<ByteBuffer> GzipDecompressor::decompress_all(ReadonlyBytes bytes)
{
- auto memory_stream = TRY(FixedMemoryStream::construct(bytes));
+ auto memory_stream = TRY(try_make<FixedMemoryStream>(bytes));
auto gzip_stream = make<GzipDecompressor>(move(memory_stream));
AllocatingMemoryStream output_stream;
diff --git a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp b/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp
index e8c263ffa6..67f926a43e 100644
--- a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp
+++ b/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp
@@ -21,19 +21,19 @@ AbbreviationsMap::AbbreviationsMap(DwarfInfo const& dwarf_info, u32 offset)
ErrorOr<void> AbbreviationsMap::populate_map()
{
- auto abbreviation_stream = TRY(FixedMemoryStream::construct(m_dwarf_info.abbreviation_data()));
- TRY(abbreviation_stream->discard(m_offset));
+ FixedMemoryStream abbreviation_stream { m_dwarf_info.abbreviation_data() };
+ TRY(abbreviation_stream.discard(m_offset));
- while (!abbreviation_stream->is_eof()) {
- size_t abbreviation_code = TRY(abbreviation_stream->read_value<LEB128<size_t>>());
+ while (!abbreviation_stream.is_eof()) {
+ size_t abbreviation_code = TRY(abbreviation_stream.read_value<LEB128<size_t>>());
// An abbreviation code of 0 marks the end of the
// abbreviations for a given compilation unit
if (abbreviation_code == 0)
break;
- size_t tag = TRY(abbreviation_stream->read_value<LEB128<size_t>>());
+ size_t tag = TRY(abbreviation_stream.read_value<LEB128<size_t>>());
- auto has_children = TRY(abbreviation_stream->read_value<u8>());
+ auto has_children = TRY(abbreviation_stream.read_value<u8>());
AbbreviationEntry abbreviation_entry {};
abbreviation_entry.tag = static_cast<EntryTag>(tag);
@@ -41,14 +41,14 @@ ErrorOr<void> AbbreviationsMap::populate_map()
AttributeSpecification current_attribute_specification {};
do {
- size_t attribute_value = TRY(abbreviation_stream->read_value<LEB128<size_t>>());
- size_t form_value = TRY(abbreviation_stream->read_value<LEB128<size_t>>());
+ size_t attribute_value = TRY(abbreviation_stream.read_value<LEB128<size_t>>());
+ size_t form_value = TRY(abbreviation_stream.read_value<LEB128<size_t>>());
current_attribute_specification.attribute = static_cast<Attribute>(attribute_value);
current_attribute_specification.form = static_cast<AttributeDataForm>(form_value);
if (current_attribute_specification.form == AttributeDataForm::ImplicitConst) {
- ssize_t data_value = TRY(abbreviation_stream->read_value<LEB128<ssize_t>>());
+ ssize_t data_value = TRY(abbreviation_stream.read_value<LEB128<ssize_t>>());
current_attribute_specification.value = data_value;
}
diff --git a/Userland/Libraries/LibDebug/Dwarf/AddressRanges.h b/Userland/Libraries/LibDebug/Dwarf/AddressRanges.h
index 4f4a82985f..7849b9778d 100644
--- a/Userland/Libraries/LibDebug/Dwarf/AddressRanges.h
+++ b/Userland/Libraries/LibDebug/Dwarf/AddressRanges.h
@@ -24,6 +24,7 @@ class AddressRangesV5 {
AK_MAKE_NONMOVABLE(AddressRangesV5);
public:
+ // FIXME: This should be fine with using a non-owned stream.
AddressRangesV5(NonnullOwnPtr<AK::Stream> range_lists_stream, CompilationUnit const& compilation_unit);
ErrorOr<void> for_each_range(Function<void(Range)>);
diff --git a/Userland/Libraries/LibDebug/Dwarf/DIE.cpp b/Userland/Libraries/LibDebug/Dwarf/DIE.cpp
index a9e0cef979..2d2c5154c1 100644
--- a/Userland/Libraries/LibDebug/Dwarf/DIE.cpp
+++ b/Userland/Libraries/LibDebug/Dwarf/DIE.cpp
@@ -23,11 +23,11 @@ ErrorOr<void> DIE::rehydrate_from(u32 offset, Optional<u32> parent_offset)
{
m_offset = offset;
- auto stream = TRY(FixedMemoryStream::construct(m_compilation_unit.dwarf_info().debug_info_data()));
+ FixedMemoryStream stream { m_compilation_unit.dwarf_info().debug_info_data() };
// Note: We can't just slice away from the input data here, since get_attribute_value will try to recover the original offset using seek().
- TRY(stream->seek(m_offset));
- m_abbreviation_code = TRY(stream->read_value<LEB128<size_t>>());
- m_data_offset = TRY(stream->tell());
+ TRY(stream.seek(m_offset));
+ m_abbreviation_code = TRY(stream.read_value<LEB128<size_t>>());
+ m_data_offset = TRY(stream.tell());
if (m_abbreviation_code == 0) {
// An abbreviation code of 0 ( = null DIE entry) means the end of a chain of siblings
@@ -41,25 +41,25 @@ ErrorOr<void> DIE::rehydrate_from(u32 offset, Optional<u32> parent_offset)
// We iterate the attributes data only to calculate this DIE's size
for (auto& attribute_spec : abbreviation_info->attribute_specifications) {
- TRY(m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, *stream, &m_compilation_unit));
+ TRY(m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, stream, &m_compilation_unit));
}
}
- m_size = TRY(stream->tell()) - m_offset;
+ m_size = TRY(stream.tell()) - m_offset;
m_parent_offset = parent_offset;
return {};
}
ErrorOr<Optional<AttributeValue>> DIE::get_attribute(Attribute const& attribute) const
{
- auto stream = TRY(FixedMemoryStream::construct(m_compilation_unit.dwarf_info().debug_info_data()));
+ FixedMemoryStream stream { m_compilation_unit.dwarf_info().debug_info_data() };
// Note: We can't just slice away from the input data here, since get_attribute_value will try to recover the original offset using seek().
- TRY(stream->seek(m_data_offset));
+ TRY(stream.seek(m_data_offset));
auto abbreviation_info = m_compilation_unit.abbreviations_map().get(m_abbreviation_code);
VERIFY(abbreviation_info);
for (auto const& attribute_spec : abbreviation_info->attribute_specifications) {
- auto value = TRY(m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, *stream, &m_compilation_unit));
+ auto value = TRY(m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, stream, &m_compilation_unit));
if (attribute_spec.attribute == attribute) {
return value;
}
diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp
index b4b519cdaf..6d52ecf8b7 100644
--- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp
+++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp
@@ -47,35 +47,35 @@ ErrorOr<void> DwarfInfo::populate_compilation_units()
if (!m_debug_info_data.data())
return {};
- auto debug_info_stream = TRY(FixedMemoryStream::construct(m_debug_info_data));
- auto line_info_stream = TRY(FixedMemoryStream::construct(m_debug_line_data));
+ FixedMemoryStream debug_info_stream { m_debug_info_data };
+ FixedMemoryStream line_info_stream { m_debug_line_data };
- while (!debug_info_stream->is_eof()) {
- auto unit_offset = TRY(debug_info_stream->tell());
+ while (!debug_info_stream.is_eof()) {
+ auto unit_offset = TRY(debug_info_stream.tell());
- auto compilation_unit_header = TRY(debug_info_stream->read_value<CompilationUnitHeader>());
+ auto compilation_unit_header = TRY(debug_info_stream.read_value<CompilationUnitHeader>());
VERIFY(compilation_unit_header.common.version <= 5);
VERIFY(compilation_unit_header.address_size() == sizeof(FlatPtr));
u32 length_after_header = compilation_unit_header.length() - (compilation_unit_header.header_size() - offsetof(CompilationUnitHeader, common.version));
- auto line_program = make<LineProgram>(*this, *line_info_stream);
+ auto line_program = make<LineProgram>(*this, line_info_stream);
// HACK: Clang generates line programs for embedded resource assembly files, but not compile units.
// Meaning that for graphical applications, some line info data would be unread, triggering the assertion below.
// As a fix, we don't create compilation units for line programs that come from resource files.
#if defined(AK_COMPILER_CLANG)
if (line_program->looks_like_embedded_resource()) {
- TRY(debug_info_stream->seek(unit_offset));
+ TRY(debug_info_stream.seek(unit_offset));
} else
#endif
{
m_compilation_units.append(make<CompilationUnit>(*this, unit_offset, compilation_unit_header, move(line_program)));
- TRY(debug_info_stream->discard(length_after_header));
+ TRY(debug_info_stream.discard(length_after_header));
}
}
- VERIFY(line_info_stream->is_eof());
+ VERIFY(line_info_stream.is_eof());
return {};
}
@@ -300,14 +300,14 @@ ErrorOr<void> DwarfInfo::build_cached_dies() const
Vector<DIERange> entries;
if (die.compilation_unit().dwarf_version() == 5) {
- auto range_lists_stream = TRY(FixedMemoryStream::construct(debug_range_lists_data()));
+ auto range_lists_stream = TRY(try_make<FixedMemoryStream>(debug_range_lists_data()));
TRY(range_lists_stream->seek(offset));
AddressRangesV5 address_ranges(move(range_lists_stream), die.compilation_unit());
TRY(address_ranges.for_each_range([&entries](auto range) {
entries.empend(range.start, range.end);
}));
} else {
- auto ranges_stream = TRY(FixedMemoryStream::construct(debug_ranges_data()));
+ auto ranges_stream = TRY(try_make<FixedMemoryStream>(debug_ranges_data()));
TRY(ranges_stream->seek(offset));
AddressRangesV4 address_ranges(move(ranges_stream), die.compilation_unit());
TRY(address_ranges.for_each_range([&entries](auto range) {
diff --git a/Userland/Libraries/LibDebug/Dwarf/Expression.cpp b/Userland/Libraries/LibDebug/Dwarf/Expression.cpp
index 373bf26940..30f45f6e4b 100644
--- a/Userland/Libraries/LibDebug/Dwarf/Expression.cpp
+++ b/Userland/Libraries/LibDebug/Dwarf/Expression.cpp
@@ -14,10 +14,10 @@ namespace Debug::Dwarf::Expression {
ErrorOr<Value> evaluate(ReadonlyBytes bytes, [[maybe_unused]] PtraceRegisters const& regs)
{
- auto stream = TRY(FixedMemoryStream::construct(bytes));
+ FixedMemoryStream stream { bytes };
- while (!stream->is_eof()) {
- auto opcode = TRY(stream->read_value<u8>());
+ while (!stream.is_eof()) {
+ auto opcode = TRY(stream.read_value<u8>());
switch (static_cast<Operations>(opcode)) {
diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp
index 6535980ecf..dbf76239b1 100644
--- a/Userland/Libraries/LibGfx/GIFLoader.cpp
+++ b/Userland/Libraries/LibGfx/GIFLoader.cpp
@@ -381,21 +381,21 @@ static ErrorOr<void> load_gif_frame_descriptors(GIFLoadingContext& context)
if (context.data_size < 32)
return Error::from_string_literal("Size too short for GIF frame descriptors");
- auto stream = TRY(FixedMemoryStream::construct(ReadonlyBytes { context.data, context.data_size }));
+ FixedMemoryStream stream { { context.data, context.data_size } };
- TRY(decode_gif_header(*stream));
+ TRY(decode_gif_header(stream));
- context.logical_screen.width = TRY(stream->read_value<LittleEndian<u16>>());
- context.logical_screen.height = TRY(stream->read_value<LittleEndian<u16>>());
+ context.logical_screen.width = TRY(stream.read_value<LittleEndian<u16>>());
+ context.logical_screen.height = TRY(stream.read_value<LittleEndian<u16>>());
if (context.logical_screen.width > maximum_width_for_decoded_images || context.logical_screen.height > maximum_height_for_decoded_images) {
dbgln("This GIF is too large for comfort: {}x{}", context.logical_screen.width, context.logical_screen.height);
return Error::from_string_literal("This GIF is too large for comfort");
}
- auto gcm_info = TRY(stream->read_value<u8>());
- context.background_color_index = TRY(stream->read_value<u8>());
- [[maybe_unused]] auto pixel_aspect_ratio = TRY(stream->read_value<u8>());
+ auto gcm_info = TRY(stream.read_value<u8>());
+ context.background_color_index = TRY(stream.read_value<u8>());
+ [[maybe_unused]] auto pixel_aspect_ratio = TRY(stream.read_value<u8>());
u8 bits_per_pixel = (gcm_info & 7) + 1;
int color_map_entry_count = 1;
@@ -403,29 +403,29 @@ static ErrorOr<void> load_gif_frame_descriptors(GIFLoadingContext& context)
color_map_entry_count *= 2;
for (int i = 0; i < color_map_entry_count; ++i) {
- u8 r = TRY(stream->read_value<u8>());
- u8 g = TRY(stream->read_value<u8>());
- u8 b = TRY(stream->read_value<u8>());
+ u8 r = TRY(stream.read_value<u8>());
+ u8 g = TRY(stream.read_value<u8>());
+ u8 b = TRY(stream.read_value<u8>());
context.logical_screen.color_map[i] = { r, g, b };
}
NonnullOwnPtr<GIFImageDescriptor> current_image = make<GIFImageDescriptor>();
for (;;) {
- u8 sentinel = TRY(stream->read_value<u8>());
+ u8 sentinel = TRY(stream.read_value<u8>());
if (sentinel == '!') {
- u8 extension_type = TRY(stream->read_value<u8>());
+ u8 extension_type = TRY(stream.read_value<u8>());
u8 sub_block_length = 0;
Vector<u8> sub_block {};
for (;;) {
- sub_block_length = TRY(stream->read_value<u8>());
+ sub_block_length = TRY(stream.read_value<u8>());
if (sub_block_length == 0)
break;
TRY(sub_block.try_resize(sub_block.size() + sub_block_length));
- TRY(stream->read_entire_buffer(sub_block.span().slice_from_end(sub_block_length)));
+ TRY(stream.read_entire_buffer(sub_block.span().slice_from_end(sub_block_length)));
}
if (extension_type == 0xF9) {
@@ -471,12 +471,12 @@ static ErrorOr<void> load_gif_frame_descriptors(GIFLoadingContext& context)
context.images.append(move(current_image));
auto& image = context.images.last();
- image.x = TRY(stream->read_value<LittleEndian<u16>>());
- image.y = TRY(stream->read_value<LittleEndian<u16>>());
- image.width = TRY(stream->read_value<LittleEndian<u16>>());
- image.height = TRY(stream->read_value<LittleEndian<u16>>());
+ image.x = TRY(stream.read_value<LittleEndian<u16>>());
+ image.y = TRY(stream.read_value<LittleEndian<u16>>());
+ image.width = TRY(stream.read_value<LittleEndian<u16>>());
+ image.height = TRY(stream.read_value<LittleEndian<u16>>());
- auto packed_fields = TRY(stream->read_value<u8>());
+ auto packed_fields = TRY(stream.read_value<u8>());
image.use_global_color_map = !(packed_fields & 0x80);
image.interlaced = (packed_fields & 0x40) != 0;
@@ -485,24 +485,24 @@ static ErrorOr<void> load_gif_frame_descriptors(GIFLoadingContext& context)
size_t local_color_table_size = AK::exp2<size_t>((packed_fields & 7) + 1);
for (size_t i = 0; i < local_color_table_size; ++i) {
- u8 r = TRY(stream->read_value<u8>());
- u8 g = TRY(stream->read_value<u8>());
- u8 b = TRY(stream->read_value<u8>());
+ u8 r = TRY(stream.read_value<u8>());
+ u8 g = TRY(stream.read_value<u8>());
+ u8 b = TRY(stream.read_value<u8>());
image.color_map[i] = { r, g, b };
}
}
- image.lzw_min_code_size = TRY(stream->read_value<u8>());
+ image.lzw_min_code_size = TRY(stream.read_value<u8>());
u8 lzw_encoded_bytes_expected = 0;
for (;;) {
- lzw_encoded_bytes_expected = TRY(stream->read_value<u8>());
+ lzw_encoded_bytes_expected = TRY(stream.read_value<u8>());
if (lzw_encoded_bytes_expected == 0)
break;
Array<u8, 256> buffer;
- TRY(stream->read_entire_buffer(buffer.span().trim(lzw_encoded_bytes_expected)));
+ TRY(stream.read_entire_buffer(buffer.span().trim(lzw_encoded_bytes_expected)));
for (int i = 0; i < lzw_encoded_bytes_expected; ++i) {
image.lzw_encoded_bytes.append(buffer[i]);
@@ -565,16 +565,14 @@ bool GIFImageDecoderPlugin::set_nonvolatile(bool& was_purged)
bool GIFImageDecoderPlugin::initialize()
{
- auto stream_or_error = FixedMemoryStream::construct(ReadonlyBytes { m_context->data, m_context->data_size });
- if (stream_or_error.is_error())
- return false;
- return !decode_gif_header(*stream_or_error.value()).is_error();
+ FixedMemoryStream stream { { m_context->data, m_context->data_size } };
+ return !decode_gif_header(stream).is_error();
}
ErrorOr<bool> GIFImageDecoderPlugin::sniff(ReadonlyBytes data)
{
- auto stream = TRY(FixedMemoryStream::construct(data));
- return !decode_gif_header(*stream).is_error();
+ FixedMemoryStream stream { data };
+ return !decode_gif_header(stream).is_error();
}
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> GIFImageDecoderPlugin::create(ReadonlyBytes data)
diff --git a/Userland/Libraries/LibGfx/ICOLoader.cpp b/Userland/Libraries/LibGfx/ICOLoader.cpp
index 9007d06a90..ad4fcb5edf 100644
--- a/Userland/Libraries/LibGfx/ICOLoader.cpp
+++ b/Userland/Libraries/LibGfx/ICOLoader.cpp
@@ -116,14 +116,14 @@ static size_t find_largest_image(ICOLoadingContext const& context)
static ErrorOr<void> load_ico_directory(ICOLoadingContext& context)
{
- auto stream = TRY(FixedMemoryStream::construct({ context.data, context.data_size }));
+ FixedMemoryStream stream { { context.data, context.data_size } };
- auto image_count = TRY(decode_ico_header(*stream));
+ auto image_count = TRY(decode_ico_header(stream));
if (image_count == 0)
return Error::from_string_literal("ICO file has no images");
for (size_t i = 0; i < image_count; ++i) {
- auto desc = TRY(decode_ico_direntry(*stream));
+ auto desc = TRY(decode_ico_direntry(stream));
if (desc.offset + desc.size < desc.offset // detect integer overflow
|| (desc.offset + desc.size) > context.data_size) {
dbgln_if(ICO_DEBUG, "load_ico_directory: offset: {} size: {} doesn't fit in ICO size: {}", desc.offset, desc.size, context.data_size);
@@ -183,8 +183,8 @@ ErrorOr<void> ICOImageDecoderPlugin::load_ico_bitmap(ICOLoadingContext& context,
ErrorOr<bool> ICOImageDecoderPlugin::sniff(ReadonlyBytes data)
{
- auto stream = TRY(FixedMemoryStream::construct(data));
- return !decode_ico_header(*stream).is_error();
+ FixedMemoryStream stream { data };
+ return !decode_ico_header(stream).is_error();
}
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> ICOImageDecoderPlugin::create(ReadonlyBytes data)
@@ -233,10 +233,8 @@ bool ICOImageDecoderPlugin::set_nonvolatile(bool& was_purged)
bool ICOImageDecoderPlugin::initialize()
{
- auto stream_or_error = FixedMemoryStream::construct(ReadonlyBytes { m_context->data, m_context->data_size });
- if (stream_or_error.is_error())
- return false;
- return !decode_ico_header(*stream_or_error.value()).is_error();
+ FixedMemoryStream stream { { m_context->data, m_context->data_size } };
+ return !decode_ico_header(stream).is_error();
}
bool ICOImageDecoderPlugin::is_animated()
diff --git a/Userland/Libraries/LibGfx/JPGLoader.cpp b/Userland/Libraries/LibGfx/JPGLoader.cpp
index 8f67d4f746..3fe1d8f297 100644
--- a/Userland/Libraries/LibGfx/JPGLoader.cpp
+++ b/Userland/Libraries/LibGfx/JPGLoader.cpp
@@ -1202,7 +1202,7 @@ static ErrorOr<void> scan_huffman_stream(AK::SeekableStream& stream, JPGLoadingC
static ErrorOr<void> decode_header(JPGLoadingContext& context)
{
if (context.state < JPGLoadingContext::State::HeaderDecoded) {
- context.stream = TRY(FixedMemoryStream::construct({ context.data, context.data_size }));
+ context.stream = TRY(try_make<FixedMemoryStream>(ReadonlyBytes { context.data, context.data_size }));
if (auto result = parse_header(*context.stream, context); result.is_error()) {
context.state = JPGLoadingContext::State::Error;
diff --git a/Userland/Libraries/LibGfx/QOILoader.cpp b/Userland/Libraries/LibGfx/QOILoader.cpp
index 0ecbed76cf..0f633d567c 100644
--- a/Userland/Libraries/LibGfx/QOILoader.cpp
+++ b/Userland/Libraries/LibGfx/QOILoader.cpp
@@ -202,13 +202,13 @@ bool QOIImageDecoderPlugin::initialize()
ErrorOr<bool> QOIImageDecoderPlugin::sniff(ReadonlyBytes data)
{
- auto stream = TRY(FixedMemoryStream::construct({ data.data(), data.size() }));
- return !decode_qoi_header(*stream).is_error();
+ FixedMemoryStream stream { { data.data(), data.size() } };
+ return !decode_qoi_header(stream).is_error();
}
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> QOIImageDecoderPlugin::create(ReadonlyBytes data)
{
- auto stream = TRY(FixedMemoryStream::construct(data));
+ auto stream = TRY(try_make<FixedMemoryStream>(data));
return adopt_nonnull_own_or_enomem(new (nothrow) QOIImageDecoderPlugin(move(stream)));
}
diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp
index 4ae7724a9d..a15e8ddb90 100644
--- a/Userland/Libraries/LibHTTP/Job.cpp
+++ b/Userland/Libraries/LibHTTP/Job.cpp
@@ -70,8 +70,8 @@ static ErrorOr<ByteBuffer> handle_content_encoding(ByteBuffer const& buf, Deprec
} else if (content_encoding == "br") {
dbgln_if(JOB_DEBUG, "Job::handle_content_encoding: buf is brotli compressed!");
- auto bufstream = TRY(FixedMemoryStream::construct({ buf.data(), buf.size() }));
- auto brotli_stream = Compress::BrotliDecompressionStream { *bufstream };
+ FixedMemoryStream bufstream { buf };
+ auto brotli_stream = Compress::BrotliDecompressionStream { bufstream };
auto uncompressed = TRY(brotli_stream.read_until_eof());
if constexpr (JOB_DEBUG) {
diff --git a/Userland/Libraries/LibPDF/DocumentParser.cpp b/Userland/Libraries/LibPDF/DocumentParser.cpp
index 08ab129847..2b55aea802 100644
--- a/Userland/Libraries/LibPDF/DocumentParser.cpp
+++ b/Userland/Libraries/LibPDF/DocumentParser.cpp
@@ -596,7 +596,7 @@ PDFErrorOr<DocumentParser::PageOffsetHintTable> DocumentParser::parse_page_offse
PDFErrorOr<Vector<DocumentParser::PageOffsetHintTableEntry>> DocumentParser::parse_all_page_offset_hint_table_entries(PageOffsetHintTable const& hint_table, ReadonlyBytes hint_stream_bytes)
{
- auto input_stream = TRY(FixedMemoryStream::construct(hint_stream_bytes));
+ auto input_stream = TRY(try_make<FixedMemoryStream>(hint_stream_bytes));
TRY(input_stream->seek(sizeof(PageOffsetHintTable)));
LittleEndianInputBitStream bit_stream { move(input_stream) };
diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp
index 2a2856e472..a1c383aa8e 100644
--- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp
+++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp
@@ -203,8 +203,8 @@ struct ConvertToRaw<float> {
{
LittleEndian<u32> res;
ReadonlyBytes bytes { &value, sizeof(float) };
- auto stream = FixedMemoryStream::construct(bytes).release_value_but_fixme_should_propagate_errors();
- stream->read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors();
+ FixedMemoryStream stream { bytes };
+ stream.read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors();
return static_cast<u32>(res);
}
};
@@ -215,8 +215,8 @@ struct ConvertToRaw<double> {
{
LittleEndian<u64> res;
ReadonlyBytes bytes { &value, sizeof(double) };
- auto stream = FixedMemoryStream::construct(bytes).release_value_but_fixme_should_propagate_errors();
- stream->read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors();
+ FixedMemoryStream stream { bytes };
+ stream.read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors();
return static_cast<u64>(res);
}
};
@@ -253,8 +253,8 @@ template<typename T>
T BytecodeInterpreter::read_value(ReadonlyBytes data)
{
LittleEndian<T> value;
- auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors();
- auto maybe_error = stream->read_entire_buffer(value.bytes());
+ FixedMemoryStream stream { data };
+ auto maybe_error = stream.read_entire_buffer(value.bytes());
if (maybe_error.is_error()) {
dbgln("Read from {} failed", data.data());
m_trap = Trap { "Read from memory failed" };
@@ -266,8 +266,8 @@ template<>
float BytecodeInterpreter::read_value<float>(ReadonlyBytes data)
{
LittleEndian<u32> raw_value;
- auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors();
- auto maybe_error = stream->read_entire_buffer(raw_value.bytes());
+ FixedMemoryStream stream { data };
+ auto maybe_error = stream.read_entire_buffer(raw_value.bytes());
if (maybe_error.is_error())
m_trap = Trap { "Read from memory failed" };
return bit_cast<float>(static_cast<u32>(raw_value));
@@ -277,8 +277,8 @@ template<>
double BytecodeInterpreter::read_value<double>(ReadonlyBytes data)
{
LittleEndian<u64> raw_value;
- auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors();
- auto maybe_error = stream->read_entire_buffer(raw_value.bytes());
+ FixedMemoryStream stream { data };
+ auto maybe_error = stream.read_entire_buffer(raw_value.bytes());
if (maybe_error.is_error())
m_trap = Trap { "Read from memory failed" };
return bit_cast<double>(static_cast<u64>(raw_value));
diff --git a/Userland/Libraries/LibWasm/Parser/Parser.cpp b/Userland/Libraries/LibWasm/Parser/Parser.cpp
index 51f72d99e1..42282fb7bd 100644
--- a/Userland/Libraries/LibWasm/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWasm/Parser/Parser.cpp
@@ -260,8 +260,8 @@ ParseResult<BlockType> BlockType::parse(AK::Stream& stream)
return BlockType {};
{
- auto value_stream = FixedMemoryStream::construct(ReadonlyBytes { &kind, 1 }).release_value_but_fixme_should_propagate_errors();
- if (auto value_type = ValueType::parse(*value_stream); !value_type.is_error())
+ FixedMemoryStream value_stream { ReadonlyBytes { &kind, 1 } };
+ if (auto value_type = ValueType::parse(value_stream); !value_type.is_error())
return BlockType { value_type.release_value() };
}
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
index bf6dc243ae..7d6ad22390 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
@@ -121,8 +121,8 @@ JS::ThrowCompletionOr<size_t> parse_module(JS::VM& vm, JS::Object* buffer_object
} else {
return vm.throw_completion<JS::TypeError>("Not a BufferSource");
}
- auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors();
- auto module_result = Wasm::Module::parse(*stream);
+ FixedMemoryStream stream { data };
+ auto module_result = Wasm::Module::parse(stream);
if (module_result.is_error()) {
// FIXME: Throw CompileError instead.
return vm.throw_completion<JS::TypeError>(Wasm::parse_error_to_deprecated_string(module_result.error()));
diff --git a/Userland/Services/WebServer/Client.cpp b/Userland/Services/WebServer/Client.cpp
index 269582af5f..beb497438b 100644
--- a/Userland/Services/WebServer/Client.cpp
+++ b/Userland/Services/WebServer/Client.cpp
@@ -336,8 +336,8 @@ ErrorOr<void> Client::handle_directory_listing(String const& requested_path, Str
builder.append("</html>\n"sv);
auto response = builder.to_deprecated_string();
- auto stream = TRY(FixedMemoryStream::construct(response.bytes()));
- return send_response(*stream, request, { .type = TRY(String::from_utf8("text/html"sv)), .length = response.length() });
+ FixedMemoryStream stream { response.bytes() };
+ return send_response(stream, request, { .type = TRY(String::from_utf8("text/html"sv)), .length = response.length() });
}
ErrorOr<void> Client::send_error_response(unsigned code, HTTP::HttpRequest const& request, Vector<String> const& headers)
diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp
index 2e339890e3..fb0e2df08b 100644
--- a/Userland/Utilities/headless-browser.cpp
+++ b/Userland/Utilities/headless-browser.cpp
@@ -342,7 +342,7 @@ public:
private:
HTTPHeadlessRequest(HTTP::HttpRequest&& request, NonnullOwnPtr<Core::Stream::BufferedSocketBase> socket, ByteBuffer&& stream_backing_buffer)
: m_stream_backing_buffer(move(stream_backing_buffer))
- , m_output_stream(FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors())
+ , m_output_stream(try_make<FixedMemoryStream>(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors())
, m_socket(move(socket))
, m_job(HTTP::Job::construct(move(request), *m_output_stream))
{
@@ -421,7 +421,7 @@ public:
private:
HTTPSHeadlessRequest(HTTP::HttpRequest&& request, NonnullOwnPtr<Core::Stream::BufferedSocketBase> socket, ByteBuffer&& stream_backing_buffer)
: m_stream_backing_buffer(move(stream_backing_buffer))
- , m_output_stream(FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors())
+ , m_output_stream(try_make<FixedMemoryStream>(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors())
, m_socket(move(socket))
, m_job(HTTP::HttpsJob::construct(move(request), *m_output_stream))
{
@@ -490,7 +490,7 @@ public:
private:
GeminiHeadlessRequest(Gemini::GeminiRequest&& request, NonnullOwnPtr<Core::Stream::BufferedSocketBase> socket, ByteBuffer&& stream_backing_buffer)
: m_stream_backing_buffer(move(stream_backing_buffer))
- , m_output_stream(FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors())
+ , m_output_stream(try_make<FixedMemoryStream>(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors())
, m_socket(move(socket))
, m_job(Gemini::Job::construct(move(request), *m_output_stream))
{
diff --git a/Userland/Utilities/wasm.cpp b/Userland/Utilities/wasm.cpp
index 0ec6e4ca76..ae368f5888 100644
--- a/Userland/Utilities/wasm.cpp
+++ b/Userland/Utilities/wasm.cpp
@@ -252,8 +252,8 @@ static Optional<Wasm::Module> parse(StringView filename)
return {};
}
- auto stream = FixedMemoryStream::construct(ReadonlyBytes { result.value()->data(), result.value()->size() }).release_value_but_fixme_should_propagate_errors();
- auto parse_result = Wasm::Module::parse(*stream);
+ FixedMemoryStream stream { ReadonlyBytes { result.value()->data(), result.value()->size() } };
+ auto parse_result = Wasm::Module::parse(stream);
if (parse_result.is_error()) {
warnln("Something went wrong, either the file is invalid, or there's a bug with LibWasm!");
warnln("The parse error was {}", Wasm::parse_error_to_deprecated_string(parse_result.error()));