From 9e6d91032eceb987e32ceb4860e7a34023ac1807 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Fri, 2 Jun 2023 11:54:23 -0400 Subject: [PATCH] LibGfx/JPEG: Use `Error` to propagate errors This patch removes a long time remnant of the pre-`AK::Error` era. --- .../LibGfx/ImageFormats/JPEGLoader.cpp | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp index 6ead2fcf53..e95862627d 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp @@ -18,8 +18,6 @@ #include #include -#define JPEG_INVALID 0X0000 - // These names are defined in B.1.1.3 - Marker assignments #define JPEG_APPN0 0XFFE0 @@ -807,18 +805,20 @@ static inline bool is_supported_marker(Marker const marker) static inline ErrorOr read_marker_at_cursor(Stream& stream) { u16 marker = TRY(stream.read_value>()); + + if (marker == 0xFFFF) { + u8 next { 0xFF }; + + while (next == 0xFF) + next = TRY(stream.read_value()); + + marker = 0xFF00 | next; + } + if (is_supported_marker(marker)) return marker; - if (marker != 0xFFFF) - return JPEG_INVALID; - u8 next; - do { - next = TRY(stream.read_value()); - if (next == 0x00) - return JPEG_INVALID; - } while (next == 0xFF); - marker = 0xFF00 | (u16)next; - return is_supported_marker(marker) ? marker : JPEG_INVALID; + + return Error::from_string_literal("Reached an unsupported marker"); } static ErrorOr read_effective_chunk_size(Stream& stream) @@ -1765,7 +1765,6 @@ static ErrorOr parse_header(Stream& stream, JPEGLoadingContext& context) context.frame.type = static_cast(marker & 0xF); switch (marker) { - case JPEG_INVALID: case JPEG_RST0: case JPEG_RST1: case JPEG_RST2: