- fixed the type checks for object arrays.

Null pointers must be allowed and non-object pointers which are not null must be explicitly checked for because the code could crash on them when performing a static_cast on an incorrect type.
This commit is contained in:
Christoph Oelckers 2018-11-18 19:48:09 +01:00
parent a8d4d45e89
commit 3aef8418d9

View file

@ -8246,12 +8246,17 @@ FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx)
} }
if (isDynArrayObj && ((MethodName == NAME_Push && idx == 0) || (MethodName == NAME_Insert && idx == 1))) if (isDynArrayObj && ((MethodName == NAME_Push && idx == 0) || (MethodName == NAME_Insert && idx == 1)))
{ {
// The DynArray_Obj declaration in dynarrays.txt doesn't support generics yet. Check the type here as if it did. // Null pointers are always valid.
if (!static_cast<PObjectPointer*>(elementType)->PointedClass()->IsAncestorOf(static_cast<PObjectPointer*>(a->ValueType)->PointedClass())) if (!a->isConstant() || static_cast<FxConstant*>(a)->GetValue().GetPointer() != nullptr)
{ {
ScriptPosition.Message(MSG_ERROR, "Type mismatch in function argument"); // The DynArray_Obj declaration in dynarrays.txt doesn't support generics yet. Check the type here as if it did.
delete this; if (!a->ValueType->isObjectPointer() ||
return nullptr; !static_cast<PObjectPointer*>(elementType)->PointedClass()->IsAncestorOf(static_cast<PObjectPointer*>(a->ValueType)->PointedClass()))
{
ScriptPosition.Message(MSG_ERROR, "Type mismatch in function argument");
delete this;
return nullptr;
}
} }
} }
if (a->IsDynamicArray()) if (a->IsDynamicArray())