- fixed missing null pointer check in BuiltinNameToClass.

This commit is contained in:
Christoph Oelckers 2017-04-14 23:06:12 +02:00
parent c73b71807b
commit ca1981c52f

View file

@ -10739,27 +10739,21 @@ FxExpression *FxClassTypeCast::Resolve(FCompileContext &ctx)
int BuiltinNameToClass(VMValue *param, TArray<VMValue> &defaultparam, int numparam, VMReturn *ret, int numret) int BuiltinNameToClass(VMValue *param, TArray<VMValue> &defaultparam, int numparam, VMReturn *ret, int numret)
{ {
assert(numparam == 2); PARAM_PROLOGUE;
assert(numret == 1); PARAM_NAME(clsname);
assert(param[0].Type == REGT_INT); PARAM_CLASS(desttype, DObject);
assert(param[1].Type == REGT_POINTER);
assert(ret->RegType == REGT_POINTER);
FName clsname = ENamedName(param[0].i); PClass *cls = nullptr;
if (clsname != NAME_None) if (clsname != NAME_None)
{ {
const PClass *cls = PClass::FindClass(clsname); cls = PClass::FindClass(clsname);
const PClass *desttype = reinterpret_cast<PClass *>(param[1].a); if (cls != nullptr && (cls->VMType == nullptr || !cls->IsDescendantOf(desttype)))
if (cls->VMType == nullptr || !cls->IsDescendantOf(desttype))
{ {
// Let the caller check this. Making this an error with a message is only taking away options from the user. // does not match required parameters or is invalid.
cls = nullptr; cls = nullptr;
} }
ret->SetPointer(const_cast<PClass *>(cls));
} }
else ret->SetPointer(nullptr); ACTION_RETURN_POINTER(cls);
return 1;
} }
ExpEmit FxClassTypeCast::Emit(VMFunctionBuilder *build) ExpEmit FxClassTypeCast::Emit(VMFunctionBuilder *build)