Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0f365abe authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Remove undefined behavior in getDisplayDecorationSupport

I3b46bae068ac3d482881dac96972a40e46581d34 introduced a bug when
converting between two different versions of DisplayDecorationSupport.
We attempt to set the member fields of an std::optional object before it
has a value. Use emplace to insert a value into the object.

Unfortunately, fixing this reveals b/241278870, which is a serious
regression. On the other hand, the current checked in code results in
undefined behavior, so prevent that. Once b/241278870 is fixed, it will
be simple to remove the check for 'false'.

Bug: 241277093
Test: manual
Change-Id: I53a56b792d99bb72d49d32b5d8f071353dae1b41
parent b50bc9cd
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -2720,12 +2720,16 @@ std::optional<DisplayDecorationSupport> SurfaceComposerClient::getDisplayDecorat
            ComposerServiceAIDL::getComposerService()->getDisplayDecorationSupport(displayToken,
                                                                                   &gsupport);
    std::optional<DisplayDecorationSupport> support;
    if (status.isOk() && gsupport.has_value()) {
        support->format = static_cast<aidl::android::hardware::graphics::common::PixelFormat>(
                gsupport->format);
        support->alphaInterpretation =
    // TODO (b/241277093): Remove `false && ` once b/241278870 is fixed.
    if (false && status.isOk() && gsupport.has_value()) {
        support.emplace(DisplayDecorationSupport{
          .format =
                static_cast<aidl::android::hardware::graphics::common::PixelFormat>(
                gsupport->format),
          .alphaInterpretation =
                static_cast<aidl::android::hardware::graphics::common::AlphaInterpretation>(
                        gsupport->alphaInterpretation);
                        gsupport->alphaInterpretation)
        });
    }
    return support;
}