From 74faacd218c8277f9b7d6e3a6215dfd38a662212 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 6 Apr 2017 20:52:03 +0200 Subject: [PATCH] - fixed: FxVMFunctionCall::GetDirectFunction did not perform any checks on the function's self pointer and failed to report a mismatch as an error. - also fixed two places in the code where the above caused some incorrect definitions not to be detected. --- src/scripting/backend/codegen.cpp | 14 +++++++------- src/scripting/backend/codegen.h | 8 ++++---- src/scripting/backend/vmbuilder.cpp | 4 +++- wadsrc/static/zscript/inventory/inventory.txt | 2 +- wadsrc/static/zscript/strife/weaponassault.txt | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 4b70717b1..93fca44ed 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -419,7 +419,7 @@ bool FxExpression::isConstant() const // //========================================================================== -VMFunction *FxExpression::GetDirectFunction(const VersionInfo &ver) +VMFunction *FxExpression::GetDirectFunction(PFunction *callingfunc, const VersionInfo &ver) { return nullptr; } @@ -8625,14 +8625,14 @@ bool FxVMFunctionCall::CheckAccessibility(const VersionInfo &ver) // //========================================================================== -VMFunction *FxVMFunctionCall::GetDirectFunction(const VersionInfo &ver) +VMFunction *FxVMFunctionCall::GetDirectFunction(PFunction *callingfunc, const VersionInfo &ver) { // If this return statement calls a non-virtual function with no arguments, // then it can be a "direct" function. That is, the DECORATE // definition can call that function directly without wrapping // it inside VM code. - if (ArgList.Size() == 0 && !(Function->Variants[0].Flags & VARF_Virtual) && CheckAccessibility(ver)) + if (ArgList.Size() == 0 && !(Function->Variants[0].Flags & VARF_Virtual) && CheckAccessibility(ver) && CheckFunctionCompatiblity(ScriptPosition, callingfunc, Function)) { unsigned imp = Function->GetImplicitArgs(); if (Function->Variants[0].ArgFlags.Size() > imp && !(Function->Variants[0].ArgFlags[imp] & VARF_Optional)) return nullptr; @@ -9558,11 +9558,11 @@ ExpEmit FxSequence::Emit(VMFunctionBuilder *build) // //========================================================================== -VMFunction *FxSequence::GetDirectFunction(const VersionInfo &ver) +VMFunction *FxSequence::GetDirectFunction(PFunction *func, const VersionInfo &ver) { if (Expressions.Size() == 1) { - return Expressions[0]->GetDirectFunction(ver); + return Expressions[0]->GetDirectFunction(func, ver); } return nullptr; } @@ -10544,11 +10544,11 @@ ExpEmit FxReturnStatement::Emit(VMFunctionBuilder *build) return out; } -VMFunction *FxReturnStatement::GetDirectFunction(const VersionInfo &ver) +VMFunction *FxReturnStatement::GetDirectFunction(PFunction *func, const VersionInfo &ver) { if (Args.Size() == 1) { - return Args[0]->GetDirectFunction(ver); + return Args[0]->GetDirectFunction(func, ver); } return nullptr; } diff --git a/src/scripting/backend/codegen.h b/src/scripting/backend/codegen.h index 2974866ca..f90a03a53 100644 --- a/src/scripting/backend/codegen.h +++ b/src/scripting/backend/codegen.h @@ -324,7 +324,7 @@ public: virtual bool isConstant() const; virtual bool RequestAddress(FCompileContext &ctx, bool *writable); virtual PPrototype *ReturnProto(); - virtual VMFunction *GetDirectFunction(const VersionInfo &ver); + virtual VMFunction *GetDirectFunction(PFunction *func, const VersionInfo &ver); virtual bool CheckReturn() { return false; } virtual int GetBitValue() { return -1; } bool IsNumeric() const { return ValueType->isNumeric(); } @@ -1721,7 +1721,7 @@ public: ~FxVMFunctionCall(); FxExpression *Resolve(FCompileContext&); PPrototype *ReturnProto(); - VMFunction *GetDirectFunction(const VersionInfo &ver); + VMFunction *GetDirectFunction(PFunction *func, const VersionInfo &ver); ExpEmit Emit(VMFunctionBuilder *build); bool CheckEmitCast(VMFunctionBuilder *build, bool returnit, ExpEmit ®); TArray &GetReturnTypes() const @@ -1746,7 +1746,7 @@ public: FxExpression *Resolve(FCompileContext&); ExpEmit Emit(VMFunctionBuilder *build); void Add(FxExpression *expr) { if (expr != NULL) Expressions.Push(expr); expr->NeedResult = false; } - VMFunction *GetDirectFunction(const VersionInfo &ver); + VMFunction *GetDirectFunction(PFunction *func, const VersionInfo &ver); bool CheckReturn(); }; @@ -1953,7 +1953,7 @@ public: ~FxReturnStatement(); FxExpression *Resolve(FCompileContext&); ExpEmit Emit(VMFunctionBuilder *build); - VMFunction *GetDirectFunction(const VersionInfo &ver); + VMFunction *GetDirectFunction(PFunction *func, const VersionInfo &ver); bool CheckReturn() { return true; } }; diff --git a/src/scripting/backend/vmbuilder.cpp b/src/scripting/backend/vmbuilder.cpp index e4682432c..1543becd1 100644 --- a/src/scripting/backend/vmbuilder.cpp +++ b/src/scripting/backend/vmbuilder.cpp @@ -804,10 +804,12 @@ FFunctionBuildList FunctionBuildList; VMFunction *FFunctionBuildList::AddFunction(PNamespace *gnspc, const VersionInfo &ver, PFunction *functype, FxExpression *code, const FString &name, bool fromdecorate, int stateindex, int statecount, int lumpnum) { - auto func = code->GetDirectFunction(ver); + auto func = code->GetDirectFunction(functype, ver); if (func != nullptr) { delete code; + + return func; } diff --git a/wadsrc/static/zscript/inventory/inventory.txt b/wadsrc/static/zscript/inventory/inventory.txt index c526939a1..fe371ebea 100644 --- a/wadsrc/static/zscript/inventory/inventory.txt +++ b/wadsrc/static/zscript/inventory/inventory.txt @@ -53,7 +53,7 @@ class Inventory : Actor native native void ModifyDropAmount(int dropamount); native static void PrintPickupMessage (bool localview, String str); - States(Actor, Overlay, Weapon, Item) + States(Actor) { HideDoomish: TNT1 A 1050; diff --git a/wadsrc/static/zscript/strife/weaponassault.txt b/wadsrc/static/zscript/strife/weaponassault.txt index c382d8e84..c61951e1a 100644 --- a/wadsrc/static/zscript/strife/weaponassault.txt +++ b/wadsrc/static/zscript/strife/weaponassault.txt @@ -45,7 +45,7 @@ extend class StateProvider // //============================================================================ - void A_FireAssaultGun() + action void A_FireAssaultGun() { if (player == null) {