diff options
author | Lucas CHOLLET <lucas.chollet@free.fr> | 2023-03-12 23:03:08 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-03-24 10:56:58 +0100 |
commit | fd04b2dc9ba3883ed5599bcc80b1fdef780b5725 (patch) | |
tree | e9c7a5944fccbaf09ffc6065487447b5e1d30d46 | |
parent | 7ec310384a99e8caa93822b7efb4cfec8e5038e4 (diff) | |
download | serenity-fd04b2dc9ba3883ed5599bcc80b1fdef780b5725.zip |
LibGfx/PortableFormat: Propagate errors from `decode()`
-rw-r--r-- | Userland/Libraries/LibGfx/ImageFormats/PortableImageLoaderCommon.h | 43 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/ImageFormats/PortableImageMapLoader.h | 11 |
2 files changed, 20 insertions, 34 deletions
diff --git a/Userland/Libraries/LibGfx/ImageFormats/PortableImageLoaderCommon.h b/Userland/Libraries/LibGfx/ImageFormats/PortableImageLoaderCommon.h index 39c635db4b..0733774a07 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/PortableImageLoaderCommon.h +++ b/Userland/Libraries/LibGfx/ImageFormats/PortableImageLoaderCommon.h @@ -184,52 +184,35 @@ static void set_pixels(TContext& context, Vector<Gfx::Color> const& color_data) } template<typename TContext> -static bool decode(TContext& context) +static ErrorOr<void> decode(TContext& context) { if (context.state >= TContext::State::Decoded) - return true; - - auto error_guard = ArmedScopeGuard([&] { - context.state = TContext::State::Error; - }); - - if (read_magic_number(context).is_error()) - return false; - - if (read_whitespace(context).is_error()) - return false; + return {}; - if (read_width(context).is_error()) - return false; + TRY(read_magic_number(context)); - if (read_whitespace(context).is_error()) - return false; + TRY(read_whitespace(context)); - if (read_height(context).is_error()) - return false; + TRY(read_width(context)); + TRY(read_whitespace(context)); + TRY(read_height(context)); if (context.width > maximum_width_for_decoded_images || context.height > maximum_height_for_decoded_images) { dbgln("This portable network image is too large for comfort: {}x{}", context.width, context.height); - return false; + return Error::from_string_literal("This portable network image is too large."); } - if (read_whitespace(context).is_error()) - return false; + TRY(read_whitespace(context)); if constexpr (requires { context.format_details.max_val; }) { - if (read_max_val(context).is_error()) - return false; - - if (read_whitespace(context).is_error()) - return false; + TRY(read_max_val(context)); + TRY(read_whitespace(context)); } - if (read_image_data(context).is_error()) - return false; + TRY(read_image_data(context)); - error_guard.disarm(); context.state = TContext::State::Decoded; - return true; + return {}; } } diff --git a/Userland/Libraries/LibGfx/ImageFormats/PortableImageMapLoader.h b/Userland/Libraries/LibGfx/ImageFormats/PortableImageMapLoader.h index 5698df5eb5..0fff8600de 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/PortableImageMapLoader.h +++ b/Userland/Libraries/LibGfx/ImageFormats/PortableImageMapLoader.h @@ -93,9 +93,11 @@ IntSize PortableImageDecoderPlugin<TContext>::size() return {}; if (m_context->state < TContext::State::Decoded) { - bool success = decode(*m_context); - if (!success) + if (decode(*m_context).is_error()) { + m_context->state = TContext::State::Error; + // FIXME: We should propagate errors return {}; + } } return { m_context->width, m_context->height }; @@ -168,9 +170,10 @@ ErrorOr<ImageFrameDescriptor> PortableImageDecoderPlugin<TContext>::frame(size_t return Error::from_string_literal("PortableImageDecoderPlugin: Decoding failed"); if (m_context->state < TContext::State::Decoded) { - bool success = decode(*m_context); - if (!success) + if (decode(*m_context).is_error()) { + m_context->state = TContext::State::Error; return Error::from_string_literal("PortableImageDecoderPlugin: Decoding failed"); + } } VERIFY(m_context->bitmap); |