diff options
author | MacDue <macdue@dueutil.tech> | 2023-02-26 18:02:50 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-02-26 19:43:17 +0100 |
commit | 6cf8eeb7a46f72b48510ad8f4c6b32cb255e0404 (patch) | |
tree | 1eab3f938dae61649b1230d35becfbc58c85d132 /Userland | |
parent | 8d9cb538d6abc20cc34200e4835f5ac142e066f4 (diff) | |
download | serenity-6cf8eeb7a46f72b48510ad8f4c6b32cb255e0404.zip |
LibGfx: Return bool not ErrorOr<bool> from ImageDecoderPlugin::sniff()
Nobody made use of the ErrorOr return value and it just added more
chance of confusion, since it was not clear if failing to sniff an
image should return an error or false. The answer was false, if you
returned Error you'd crash the ImageDecoder.
Diffstat (limited to 'Userland')
21 files changed, 26 insertions, 26 deletions
diff --git a/Userland/Libraries/LibGUI/FileIconProvider.cpp b/Userland/Libraries/LibGUI/FileIconProvider.cpp index d0f603ac75..0b58a83b13 100644 --- a/Userland/Libraries/LibGUI/FileIconProvider.cpp +++ b/Userland/Libraries/LibGUI/FileIconProvider.cpp @@ -210,7 +210,7 @@ Icon FileIconProvider::icon_for_executable(DeprecatedString const& path) bitmap = s_executable_icon.bitmap_for_size(icon_section.image_size); } else { // FIXME: Use the ImageDecoder service. - if (Gfx::PNGImageDecoderPlugin::sniff({ section->raw_data(), section->size() }).release_value_but_fixme_should_propagate_errors()) { + if (Gfx::PNGImageDecoderPlugin::sniff({ section->raw_data(), section->size() })) { auto png_decoder = Gfx::PNGImageDecoderPlugin::create({ section->raw_data(), section->size() }).release_value_but_fixme_should_propagate_errors(); if (png_decoder->initialize()) { auto frame_or_error = png_decoder->frame(0); diff --git a/Userland/Libraries/LibGfx/BMPLoader.cpp b/Userland/Libraries/LibGfx/BMPLoader.cpp index ba2d4cd444..7abfffad81 100644 --- a/Userland/Libraries/LibGfx/BMPLoader.cpp +++ b/Userland/Libraries/LibGfx/BMPLoader.cpp @@ -1505,7 +1505,7 @@ bool BMPImageDecoderPlugin::initialize() return !decode_bmp_header(*m_context).is_error(); } -ErrorOr<bool> BMPImageDecoderPlugin::sniff(ReadonlyBytes data) +bool BMPImageDecoderPlugin::sniff(ReadonlyBytes data) { BMPLoadingContext context; context.file_bytes = data.data(); diff --git a/Userland/Libraries/LibGfx/BMPLoader.h b/Userland/Libraries/LibGfx/BMPLoader.h index 0880cf9112..6430d66f94 100644 --- a/Userland/Libraries/LibGfx/BMPLoader.h +++ b/Userland/Libraries/LibGfx/BMPLoader.h @@ -16,7 +16,7 @@ class ICOImageDecoderPlugin; class BMPImageDecoderPlugin final : public ImageDecoderPlugin { public: - static ErrorOr<bool> sniff(ReadonlyBytes); + static bool sniff(ReadonlyBytes); static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes); static ErrorOr<NonnullOwnPtr<BMPImageDecoderPlugin>> create_as_included_in_ico(Badge<ICOImageDecoderPlugin>, ReadonlyBytes); diff --git a/Userland/Libraries/LibGfx/DDSLoader.cpp b/Userland/Libraries/LibGfx/DDSLoader.cpp index cd52d8d615..f2775dbfee 100644 --- a/Userland/Libraries/LibGfx/DDSLoader.cpp +++ b/Userland/Libraries/LibGfx/DDSLoader.cpp @@ -656,7 +656,7 @@ bool DDSImageDecoderPlugin::initialize() && m_context->data[3] == 0x20; } -ErrorOr<bool> DDSImageDecoderPlugin::sniff(ReadonlyBytes data) +bool DDSImageDecoderPlugin::sniff(ReadonlyBytes data) { // The header is always at least 128 bytes, so if the file is smaller, it can't be a DDS. return data.size() > 128 diff --git a/Userland/Libraries/LibGfx/DDSLoader.h b/Userland/Libraries/LibGfx/DDSLoader.h index 21f79bbec2..bc9c6e250f 100644 --- a/Userland/Libraries/LibGfx/DDSLoader.h +++ b/Userland/Libraries/LibGfx/DDSLoader.h @@ -235,7 +235,7 @@ struct DDSLoadingContext; class DDSImageDecoderPlugin final : public ImageDecoderPlugin { public: - static ErrorOr<bool> sniff(ReadonlyBytes); + static bool sniff(ReadonlyBytes); static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes); virtual ~DDSImageDecoderPlugin() override; diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp index d952d05ed7..215d5d1d3d 100644 --- a/Userland/Libraries/LibGfx/GIFLoader.cpp +++ b/Userland/Libraries/LibGfx/GIFLoader.cpp @@ -569,7 +569,7 @@ bool GIFImageDecoderPlugin::initialize() return !decode_gif_header(stream).is_error(); } -ErrorOr<bool> GIFImageDecoderPlugin::sniff(ReadonlyBytes data) +bool GIFImageDecoderPlugin::sniff(ReadonlyBytes data) { FixedMemoryStream stream { data }; return !decode_gif_header(stream).is_error(); diff --git a/Userland/Libraries/LibGfx/GIFLoader.h b/Userland/Libraries/LibGfx/GIFLoader.h index 0492945f20..deaa011bea 100644 --- a/Userland/Libraries/LibGfx/GIFLoader.h +++ b/Userland/Libraries/LibGfx/GIFLoader.h @@ -15,7 +15,7 @@ struct GIFLoadingContext; class GIFImageDecoderPlugin final : public ImageDecoderPlugin { public: - static ErrorOr<bool> sniff(ReadonlyBytes); + static bool sniff(ReadonlyBytes); static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes); virtual ~GIFImageDecoderPlugin() override; diff --git a/Userland/Libraries/LibGfx/ICOLoader.cpp b/Userland/Libraries/LibGfx/ICOLoader.cpp index fb6b25baa2..d26a693c2a 100644 --- a/Userland/Libraries/LibGfx/ICOLoader.cpp +++ b/Userland/Libraries/LibGfx/ICOLoader.cpp @@ -149,7 +149,7 @@ ErrorOr<void> ICOImageDecoderPlugin::load_ico_bitmap(ICOLoadingContext& context, return Error::from_string_literal("Index out of bounds"); ICOImageDescriptor& desc = context.images[real_index]; - if (TRY(PNGImageDecoderPlugin::sniff({ context.data + desc.offset, desc.size }))) { + if (PNGImageDecoderPlugin::sniff({ context.data + desc.offset, desc.size })) { auto png_decoder = TRY(PNGImageDecoderPlugin::create({ context.data + desc.offset, desc.size })); if (png_decoder->initialize()) { auto decoded_png_frame = TRY(png_decoder->frame(0)); @@ -181,7 +181,7 @@ ErrorOr<void> ICOImageDecoderPlugin::load_ico_bitmap(ICOLoadingContext& context, } } -ErrorOr<bool> ICOImageDecoderPlugin::sniff(ReadonlyBytes data) +bool ICOImageDecoderPlugin::sniff(ReadonlyBytes data) { FixedMemoryStream stream { data }; return !decode_ico_header(stream).is_error(); diff --git a/Userland/Libraries/LibGfx/ICOLoader.h b/Userland/Libraries/LibGfx/ICOLoader.h index 8d7f1713f1..eecd7d396b 100644 --- a/Userland/Libraries/LibGfx/ICOLoader.h +++ b/Userland/Libraries/LibGfx/ICOLoader.h @@ -14,7 +14,7 @@ struct ICOLoadingContext; class ICOImageDecoderPlugin final : public ImageDecoderPlugin { public: - static ErrorOr<bool> sniff(ReadonlyBytes); + static bool sniff(ReadonlyBytes); static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes); virtual ~ICOImageDecoderPlugin() override; diff --git a/Userland/Libraries/LibGfx/ImageDecoder.cpp b/Userland/Libraries/LibGfx/ImageDecoder.cpp index 3a404d44d3..19c96d9f83 100644 --- a/Userland/Libraries/LibGfx/ImageDecoder.cpp +++ b/Userland/Libraries/LibGfx/ImageDecoder.cpp @@ -22,7 +22,7 @@ namespace Gfx { struct ImagePluginInitializer { - ErrorOr<bool> (*sniff)(ReadonlyBytes) = nullptr; + bool (*sniff)(ReadonlyBytes) = nullptr; ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> (*create)(ReadonlyBytes) = nullptr; }; @@ -53,7 +53,7 @@ static constexpr ImagePluginWithMIMETypeInitializer s_initializers_with_mime_typ static OwnPtr<ImageDecoderPlugin> probe_and_sniff_for_appropriate_plugin(ReadonlyBytes bytes) { for (auto& plugin : s_initializers) { - auto sniff_result = plugin.sniff(bytes).release_value_but_fixme_should_propagate_errors(); + auto sniff_result = plugin.sniff(bytes); if (!sniff_result) continue; auto plugin_decoder = plugin.create(bytes).release_value_but_fixme_should_propagate_errors(); diff --git a/Userland/Libraries/LibGfx/JPEGLoader.cpp b/Userland/Libraries/LibGfx/JPEGLoader.cpp index 74ff397d13..14084ab5d8 100644 --- a/Userland/Libraries/LibGfx/JPEGLoader.cpp +++ b/Userland/Libraries/LibGfx/JPEGLoader.cpp @@ -1363,7 +1363,7 @@ bool JPEGImageDecoderPlugin::initialize() return true; } -ErrorOr<bool> JPEGImageDecoderPlugin::sniff(ReadonlyBytes data) +bool JPEGImageDecoderPlugin::sniff(ReadonlyBytes data) { return data.size() > 3 && data.data()[0] == 0xFF diff --git a/Userland/Libraries/LibGfx/JPEGLoader.h b/Userland/Libraries/LibGfx/JPEGLoader.h index 146d51e52e..fd2c30ce5d 100644 --- a/Userland/Libraries/LibGfx/JPEGLoader.h +++ b/Userland/Libraries/LibGfx/JPEGLoader.h @@ -16,7 +16,7 @@ struct JPEGLoadingContext; class JPEGImageDecoderPlugin : public ImageDecoderPlugin { public: - static ErrorOr<bool> sniff(ReadonlyBytes); + static bool sniff(ReadonlyBytes); static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes); virtual ~JPEGImageDecoderPlugin() override; diff --git a/Userland/Libraries/LibGfx/PNGLoader.cpp b/Userland/Libraries/LibGfx/PNGLoader.cpp index 2578eae7ef..26a00a5908 100644 --- a/Userland/Libraries/LibGfx/PNGLoader.cpp +++ b/Userland/Libraries/LibGfx/PNGLoader.cpp @@ -1034,7 +1034,7 @@ bool PNGImageDecoderPlugin::initialize() return decode_png_header(*m_context); } -ErrorOr<bool> PNGImageDecoderPlugin::sniff(ReadonlyBytes data) +bool PNGImageDecoderPlugin::sniff(ReadonlyBytes data) { PNGLoadingContext context; context.data = data.data(); diff --git a/Userland/Libraries/LibGfx/PNGLoader.h b/Userland/Libraries/LibGfx/PNGLoader.h index 5d04e6a951..80abda9daf 100644 --- a/Userland/Libraries/LibGfx/PNGLoader.h +++ b/Userland/Libraries/LibGfx/PNGLoader.h @@ -14,7 +14,7 @@ struct PNGLoadingContext; class PNGImageDecoderPlugin final : public ImageDecoderPlugin { public: - static ErrorOr<bool> sniff(ReadonlyBytes); + static bool sniff(ReadonlyBytes); static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes); virtual ~PNGImageDecoderPlugin() override; diff --git a/Userland/Libraries/LibGfx/PortableImageMapLoader.h b/Userland/Libraries/LibGfx/PortableImageMapLoader.h index 105accc6b2..e6be567dac 100644 --- a/Userland/Libraries/LibGfx/PortableImageMapLoader.h +++ b/Userland/Libraries/LibGfx/PortableImageMapLoader.h @@ -49,7 +49,7 @@ struct PortableImageMapLoadingContext { template<typename TContext> class PortableImageDecoderPlugin final : public ImageDecoderPlugin { public: - static ErrorOr<bool> sniff(ReadonlyBytes); + static bool sniff(ReadonlyBytes); static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes); PortableImageDecoderPlugin(u8 const*, size_t); @@ -133,7 +133,7 @@ ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> PortableImageDecoderPlugin<TContext>: } template<typename TContext> -ErrorOr<bool> PortableImageDecoderPlugin<TContext>::sniff(ReadonlyBytes data) +bool PortableImageDecoderPlugin<TContext>::sniff(ReadonlyBytes data) { using Context = TContext; if (data.size() < 2) diff --git a/Userland/Libraries/LibGfx/QOILoader.cpp b/Userland/Libraries/LibGfx/QOILoader.cpp index bddf442cd3..ad6a20c78b 100644 --- a/Userland/Libraries/LibGfx/QOILoader.cpp +++ b/Userland/Libraries/LibGfx/QOILoader.cpp @@ -200,7 +200,7 @@ bool QOIImageDecoderPlugin::initialize() return !decode_header_and_update_context(*m_context->stream).is_error(); } -ErrorOr<bool> QOIImageDecoderPlugin::sniff(ReadonlyBytes data) +bool QOIImageDecoderPlugin::sniff(ReadonlyBytes data) { FixedMemoryStream stream { { data.data(), data.size() } }; return !decode_qoi_header(stream).is_error(); diff --git a/Userland/Libraries/LibGfx/QOILoader.h b/Userland/Libraries/LibGfx/QOILoader.h index e6555bdfe8..65fa373864 100644 --- a/Userland/Libraries/LibGfx/QOILoader.h +++ b/Userland/Libraries/LibGfx/QOILoader.h @@ -38,7 +38,7 @@ struct QOILoadingContext { class QOIImageDecoderPlugin final : public ImageDecoderPlugin { public: - static ErrorOr<bool> sniff(ReadonlyBytes); + static bool sniff(ReadonlyBytes); static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes); virtual ~QOIImageDecoderPlugin() override = default; diff --git a/Userland/Libraries/LibGfx/WebPLoader.cpp b/Userland/Libraries/LibGfx/WebPLoader.cpp index c1ed838fa0..d7a288d2fd 100644 --- a/Userland/Libraries/LibGfx/WebPLoader.cpp +++ b/Userland/Libraries/LibGfx/WebPLoader.cpp @@ -522,7 +522,7 @@ bool WebPImageDecoderPlugin::initialize() return !decode_webp_header(*m_context).is_error(); } -ErrorOr<bool> WebPImageDecoderPlugin::sniff(ReadonlyBytes data) +bool WebPImageDecoderPlugin::sniff(ReadonlyBytes data) { WebPLoadingContext context; context.data = data; diff --git a/Userland/Libraries/LibGfx/WebPLoader.h b/Userland/Libraries/LibGfx/WebPLoader.h index 8352093f1a..ddc82bd0f8 100644 --- a/Userland/Libraries/LibGfx/WebPLoader.h +++ b/Userland/Libraries/LibGfx/WebPLoader.h @@ -14,7 +14,7 @@ struct WebPLoadingContext; class WebPImageDecoderPlugin final : public ImageDecoderPlugin { public: - static ErrorOr<bool> sniff(ReadonlyBytes); + static bool sniff(ReadonlyBytes); static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes); virtual ~WebPImageDecoderPlugin() override; diff --git a/Userland/Libraries/LibPDF/Filter.cpp b/Userland/Libraries/LibPDF/Filter.cpp index b250101dd1..051fd445e7 100644 --- a/Userland/Libraries/LibPDF/Filter.cpp +++ b/Userland/Libraries/LibPDF/Filter.cpp @@ -269,7 +269,7 @@ ErrorOr<ByteBuffer> Filter::decode_jbig2(ReadonlyBytes) ErrorOr<ByteBuffer> Filter::decode_dct(ReadonlyBytes bytes) { - if (Gfx::JPEGImageDecoderPlugin::sniff({ bytes.data(), bytes.size() }).release_value_but_fixme_should_propagate_errors()) { + if (Gfx::JPEGImageDecoderPlugin::sniff({ bytes.data(), bytes.size() })) { auto decoder = Gfx::JPEGImageDecoderPlugin::create({ bytes.data(), bytes.size() }).release_value_but_fixme_should_propagate_errors(); if (decoder->initialize()) { auto frame = TRY(decoder->frame(0)); diff --git a/Userland/Services/SpiceAgent/SpiceAgent.cpp b/Userland/Services/SpiceAgent/SpiceAgent.cpp index 417962901a..35869eb9f3 100644 --- a/Userland/Services/SpiceAgent/SpiceAgent.cpp +++ b/Userland/Services/SpiceAgent/SpiceAgent.cpp @@ -142,19 +142,19 @@ void SpiceAgent::on_message_received() } else { ErrorOr<Gfx::ImageFrameDescriptor> frame_or_error = Gfx::ImageFrameDescriptor {}; if (type == ClipboardType::PNG) { - if (Gfx::PNGImageDecoderPlugin::sniff({ data_buffer.data(), data_buffer.size() }).release_value_but_fixme_should_propagate_errors()) { + if (Gfx::PNGImageDecoderPlugin::sniff({ data_buffer.data(), data_buffer.size() })) { auto png_decoder = Gfx::PNGImageDecoderPlugin::create({ data_buffer.data(), data_buffer.size() }).release_value_but_fixme_should_propagate_errors(); if (png_decoder->initialize()) frame_or_error = png_decoder->frame(0); } } else if (type == ClipboardType::BMP) { - if (Gfx::BMPImageDecoderPlugin::sniff({ data_buffer.data(), data_buffer.size() }).release_value_but_fixme_should_propagate_errors()) { + if (Gfx::BMPImageDecoderPlugin::sniff({ data_buffer.data(), data_buffer.size() })) { auto bmp_decoder = Gfx::BMPImageDecoderPlugin::create({ data_buffer.data(), data_buffer.size() }).release_value_but_fixme_should_propagate_errors(); if (bmp_decoder->initialize()) frame_or_error = bmp_decoder->frame(0); } } else if (type == ClipboardType::JPEG) { - if (Gfx::JPEGImageDecoderPlugin::sniff({ data_buffer.data(), data_buffer.size() }).release_value_but_fixme_should_propagate_errors()) { + if (Gfx::JPEGImageDecoderPlugin::sniff({ data_buffer.data(), data_buffer.size() })) { auto jpeg_decoder = Gfx::JPEGImageDecoderPlugin::create({ data_buffer.data(), data_buffer.size() }).release_value_but_fixme_should_propagate_errors(); if (jpeg_decoder->initialize()) frame_or_error = jpeg_decoder->frame(0); |