Bug 246248 - [GLib] JPEG2000 decoder produces warning about maybe uninitialized variable
Summary: [GLib] JPEG2000 decoder produces warning about maybe uninitialized variable
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Adrian Perez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-10-08 06:18 PDT by Adrian Perez
Modified: 2022-10-18 07:35 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adrian Perez 2022-10-08 06:18:48 PDT
Caught by Clang with -Werror=conditional-uninitialized, inside JPEG2000Decoder::decode():

/app/webkit/Source/WebCore/platform/image-decoders/jpeg2000/JPEG2000ImageDecoder.cpp:546:56: error: variable 'a' may be uninitialized when used here [-Werror,-Wconditional-uninitialized]
            int adjustedAlpha = image->numcomps > 3 ? (a >> adjust[3]) + ((a >> (adjust[3] - 1)) % 2) : 0xFF;
                                                       ^
/app/webkit/Source/WebCore/platform/image-decoders/jpeg2000/JPEG2000ImageDecoder.cpp:506:27: note: initialize the variable 'a' to silence this warning
            int r, g, b, a;
                          ^
                           = 0
1 error generated.
Comment 1 Adrian Perez 2022-10-08 06:20:44 PDT
Now that I think of it... The mishandling of alpha might related to the
decoding artifacts reported in bug #244528 (or at least be part of the
issue).
Comment 2 Adrian Perez 2022-10-08 12:47:08 PDT
Pull request: https://github.com/WebKit/WebKit/pull/5166
Comment 3 Adrian Perez 2022-10-08 12:49:36 PDT
(In reply to Adrian Perez from comment #1)
> Now that I think of it... The mishandling of alpha might related to the
> decoding artifacts reported in bug #244528 (or at least be part of the
> issue).

*Narrator voice*: It wasn´t.
Comment 4 Carlos Garcia Campos 2022-10-09 02:21:24 PDT
I don't see how this can happen because a is initialized when image->numcomps > 3 and only used when image->numcomps > 3 too.
Comment 5 Adrian Perez 2022-10-18 06:00:45 PDT
(In reply to Carlos Garcia Campos from comment #4)
> I don't see how this can happen because a is initialized when
> image->numcomps > 3 and only used when image->numcomps > 3 too.

I took another look at the code and you are right, but of course
the compiler cannot completely reason about the code and produces
a warning... so in the end I am only silencing the warning in my
patch 🤦️

Still, I think we can merge it to contribute a bit to cleaner
build output logs.
Comment 6 Carlos Garcia Campos 2022-10-18 06:14:58 PDT
Sure, it doesn't hurt, but let's change the bug title and commit message to make it clear it's not fixing anything, but just silencing a warning.
Comment 7 EWS 2022-10-18 07:34:24 PDT
Committed 255674@main (9a76ccc77f6e): <https://commits.webkit.org/255674@main>

Reviewed commits have been landed. Closing PR #5166 and removing active labels.
Comment 8 Radar WebKit Bug Importer 2022-10-18 07:35:20 PDT
<rdar://problem/101290537>