summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJooyung Han <jooyung@google.com>2021-12-11 10:16:59 +0900
committerJooyung Han <jooyung@google.com>2021-12-11 11:40:55 +0900
commit889451ed46c40eb11ac5942197c551bee2bf3ef9 (patch)
tree749c4cf5932eb60dcd58eef2ae57d3786e0e12fa
parent305af2eb093c09b4bc8efd7f24ab47f66be199ab (diff)
downloadnative-889451ed46c40eb11ac5942197c551bee2bf3ef9.tar.gz
libbinder_ndk: do not rely on copyability of parcelables
AParcel_readNullableParcelable accidentally relies on T's copyability (introduced by 3b31ccac97b070fd9e20a9d1860382af5a15fd10.) 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
-rw-r--r--libs/binder/ndk/include_cpp/android/binder_parcel_utils.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h b/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h
index 67623a6556..c1487c0bd2 100644
--- a/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h
+++ b/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h
@@ -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>);