- don't run constant state indices through the runtime checker.

This commit is contained in:
Christoph Oelckers 2016-11-05 18:15:53 +01:00
parent 1b77a8f491
commit 0851d698de
1 changed files with 24 additions and 6 deletions

View File

@ -1431,6 +1431,23 @@ FxExpression *FxTypeCast::Resolve(FCompileContext &ctx)
delete this; delete this;
return nullptr; return nullptr;
} }
if (basex->isConstant())
{
int i = static_cast<FxConstant *>(basex)->GetValue().GetInt();
if (i < 0)
{
ScriptPosition.Message(MSG_ERROR, "State index must be positive");
delete this;
return nullptr;
}
FxExpression *x = new FxStateByIndex(i, ScriptPosition);
x = x->Resolve(ctx);
basex = nullptr;
delete this;
return x;
}
else
{
FxExpression *x = new FxRuntimeStateIndex(basex); FxExpression *x = new FxRuntimeStateIndex(basex);
x = x->Resolve(ctx); x = x->Resolve(ctx);
basex = nullptr; basex = nullptr;
@ -1438,6 +1455,7 @@ FxExpression *FxTypeCast::Resolve(FCompileContext &ctx)
return x; return x;
} }
} }
}
else if (ValueType->IsKindOf(RUNTIME_CLASS(PClassPointer))) else if (ValueType->IsKindOf(RUNTIME_CLASS(PClassPointer)))
{ {
FxExpression *x = new FxClassTypeCast(static_cast<PClassPointer*>(ValueType), basex); FxExpression *x = new FxClassTypeCast(static_cast<PClassPointer*>(ValueType), basex);
@ -8019,7 +8037,7 @@ FxExpression *FxStateByIndex::Resolve(FCompileContext &ctx)
ABORT(ctx.Class); ABORT(ctx.Class);
auto aclass = dyn_cast<PClassActor>(ctx.Class); auto aclass = dyn_cast<PClassActor>(ctx.Class);
// This expression type can only be used from DECORATE, so there's no need to consider the possibility of calling it from a non-actor. // This expression type can only be used from actors, for everything else it has already produced a compile error.
assert(aclass != nullptr && aclass->NumOwnedStates > 0); assert(aclass != nullptr && aclass->NumOwnedStates > 0);
if (aclass->NumOwnedStates <= index) if (aclass->NumOwnedStates <= index)