From 8429fc812439c4da52975ecd4b2242d5774f8958 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 14 Nov 2018 10:08:04 +0100 Subject: [PATCH] - fix missing type check when using Push or Insert for typed arrays --- src/namedef.h | 2 ++ src/scripting/backend/codegen.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/namedef.h b/src/namedef.h index 5744ef4869..184c58fd0b 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -896,6 +896,8 @@ xx(DamageFunction) xx(Length) xx(Unit) xx(Size) +xx(Push) +xx(Insert) xx(Copy) xx(Move) xx(Voidptr) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index b6059a49c6..79b48953a4 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -8240,7 +8240,9 @@ FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx) { auto elementType = static_cast(Self->ValueType)->ElementType; Self->ValueType = static_cast(Self->ValueType)->BackingType; + bool isDynArrayObj = elementType->isObjectPointer(); // this requires some added type checks for the passed types. + int idx = 0; for (auto &a : ArgList) { a = a->Resolve(ctx); @@ -8249,6 +8251,16 @@ FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx) delete this; return nullptr; } + 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. + if (!static_cast(elementType)->PointedClass()->IsAncestorOf(static_cast(a->ValueType)->PointedClass())) + { + ScriptPosition.Message(MSG_ERROR, "Type mismatch in function argument"); + delete this; + return nullptr; + } + } if (a->IsDynamicArray()) { // Copy and Move must turn their parameter into a pointer to the backing struct type. @@ -8288,6 +8300,7 @@ FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx) return nullptr; } } + idx++; } } }