- 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.
This commit is contained in:
Christoph Oelckers 2017-04-06 20:52:03 +02:00
parent ca4888eb3d
commit 74faacd218
5 changed files with 16 additions and 14 deletions

View file

@ -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;
}

View file

@ -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 &reg);
TArray<PType*> &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; }
};

View file

@ -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;
}

View file

@ -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;

View file

@ -45,7 +45,7 @@ extend class StateProvider
//
//============================================================================
void A_FireAssaultGun()
action void A_FireAssaultGun()
{
if (player == null)
{