From e658d330c5c2aac5682e528bef3a373dc21b7aa9 Mon Sep 17 00:00:00 2001 From: Frederick Mayle Date: Fri, 25 Mar 2022 20:38:41 +0000 Subject: binder: Don't use reinterpret_cast to down cast In general, reinterpret_cast could do the wrong thing, e.g. if a class derived from Parcelable and added more virtual methods, then the pointer value needs to be adjusted when down casting. Test: TH Change-Id: I0d808cafa7501e9d03b83a03d1de9219bc672912 --- libs/binder/include/binder/ParcelableHolder.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/binder/include/binder/ParcelableHolder.h b/libs/binder/include/binder/ParcelableHolder.h index 42c85f9121..88790a803b 100644 --- a/libs/binder/include/binder/ParcelableHolder.h +++ b/libs/binder/include/binder/ParcelableHolder.h @@ -86,7 +86,7 @@ public: *ret = nullptr; return android::BAD_VALUE; } - *ret = std::shared_ptr(mParcelable, reinterpret_cast(mParcelable.get())); + *ret = std::static_pointer_cast(mParcelable); return android::OK; } this->mParcelPtr->setDataPosition(0); @@ -105,7 +105,7 @@ public: return status; } this->mParcelPtr = nullptr; - *ret = std::shared_ptr(mParcelable, reinterpret_cast(mParcelable.get())); + *ret = std::static_pointer_cast(mParcelable); return android::OK; } -- cgit v1.2.3-59-g8ed1b