Check for nullptr when casting IBinder to IBase.

Test: compiles

Bug: 33307202
Change-Id: I6ef880188e2f43766e52317244366b2fdd38c728
This commit is contained in:
Yifan Hong
2016-12-05 13:10:13 -08:00
parent 7241d28826
commit b747440d2f

View File

@@ -241,7 +241,14 @@ static void JHwBinder_native_registerService(
using android::hidl::manager::V1_0::IServiceManager;
sp<hardware::IBinder> binder = JHwBinder::GetNativeContext(env, thiz);
sp<hidl::base::V1_0::IBase> base = hidl::base::V1_0::IHwBase::asInterface(binder);
if (base.get() == nullptr) {
LOG(ERROR) << "IBinder object cannot be casted to the base interface.";
signalExceptionForError(env, UNKNOWN_ERROR);
return;
}
bool ok = hardware::defaultServiceManager()->add(
interfaceChain,
serviceName,