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

Commit 889451ed authored by Jooyung Han's avatar Jooyung Han
Browse files

libbinder_ndk: do not rely on copyability of parcelables

AParcel_readNullableParcelable accidentally relies on T's copyability
(introduced by 3b31ccac.)

This prevents non-copyable parcelables from being used in a nullable
arrays. For example, ScopedFileDescriptor.

The following example should be valid.

  parcelable Foo {
    parcelable Bar { ParcelFileDescriptor pfd; }
    @nullable Bar[] bars;
  }

This fixes it by using std::optional<T>::emplace().

Bug: 203483658
Test: m; build NDK with the example above.
Change-Id: If95b28869feca2114922c117b7eb618af434a535
parent 305af2eb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -560,7 +560,7 @@ static inline binder_status_t AParcel_readNullableParcelable(const AParcel* parc
            *p = std::nullopt;
            return STATUS_OK;
        }
        *p = std::optional<first_template_type_t<P>>(first_template_type_t<P>{});
        p->emplace(first_template_type_t<P>());
        return (*p)->readFromParcel(parcel);
    } else {
        static_assert(is_specialization_v<P, std::unique_ptr>);