summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Frederick Mayle <fmayle@google.com> 2022-03-25 20:38:41 +0000
committer Frederick Mayle <fmayle@google.com> 2022-03-25 20:56:31 +0000
commite658d330c5c2aac5682e528bef3a373dc21b7aa9 (patch)
treeee49e81e5fc27c667abd1b8dbbd49b393c90a33d
parent9146157b642fb149697dfea3727f64ad27a9fe8f (diff)
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
-rw-r--r--libs/binder/include/binder/ParcelableHolder.h4
1 files 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<T>(mParcelable, reinterpret_cast<T*>(mParcelable.get()));
+ *ret = std::static_pointer_cast<T>(mParcelable);
return android::OK;
}
this->mParcelPtr->setDataPosition(0);
@@ -105,7 +105,7 @@ public:
return status;
}
this->mParcelPtr = nullptr;
- *ret = std::shared_ptr<T>(mParcelable, reinterpret_cast<T*>(mParcelable.get()));
+ *ret = std::static_pointer_cast<T>(mParcelable);
return android::OK;
}