From 75a8d37c99c1fb84887dca74962cc9ca4cdf4606 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 7 Mar 2024 20:40:28 -0500 Subject: [PATCH] LibGfx: Make mime-based image loaders not throw away their error either Small follow-up to #23489. --- .../Libraries/LibGfx/ImageFormats/ImageDecoder.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.cpp b/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.cpp index d9f069e77a..813471c6b2 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.cpp @@ -61,7 +61,7 @@ static ErrorOr> probe_and_sniff_for_appropriate_plugi return OwnPtr {}; } -static OwnPtr probe_and_sniff_for_appropriate_plugin_with_known_mime_type(StringView mime_type, ReadonlyBytes bytes) +static ErrorOr> probe_and_sniff_for_appropriate_plugin_with_known_mime_type(StringView mime_type, ReadonlyBytes bytes) { struct ImagePluginWithMIMETypeInitializer { bool (*validate_before_create)(ReadonlyBytes) = nullptr; @@ -79,11 +79,9 @@ static OwnPtr probe_and_sniff_for_appropriate_plugin_with_kn auto validation_result = plugin.validate_before_create(bytes); if (!validation_result) continue; - auto plugin_decoder = plugin.create(bytes); - if (!plugin_decoder.is_error()) - return plugin_decoder.release_value(); + return TRY(plugin.create(bytes)); } - return {}; + return OwnPtr {}; } ErrorOr> ImageDecoder::try_create_for_raw_bytes(ReadonlyBytes bytes, Optional mime_type) @@ -92,7 +90,7 @@ ErrorOr> ImageDecoder::try_create_for_raw_bytes(ReadonlyByt return adopt_ref_if_nonnull(new (nothrow) ImageDecoder(plugin.release_nonnull())); if (mime_type.has_value()) { - if (OwnPtr plugin = probe_and_sniff_for_appropriate_plugin_with_known_mime_type(mime_type.value(), bytes); plugin) + if (OwnPtr plugin = TRY(probe_and_sniff_for_appropriate_plugin_with_known_mime_type(mime_type.value(), bytes)); plugin) return adopt_ref_if_nonnull(new (nothrow) ImageDecoder(plugin.release_nonnull())); }