- block "" and 0 as valid state names in ZScript. There were common workarounds for the lack of a null pointer in DECORATE which no longer are supported as those and would produce errors now.

This commit is contained in:
Christoph Oelckers 2016-11-06 12:00:16 +01:00
parent 062574b726
commit c354000f1c

View file

@ -1411,7 +1411,14 @@ FxExpression *FxTypeCast::Resolve(FCompileContext &ctx)
// Right now this only supports string constants. There should be an option to pass a string variable, too. // Right now this only supports string constants. There should be an option to pass a string variable, too.
if (basex->isConstant() && (basex->ValueType == TypeString || basex->ValueType == TypeName)) if (basex->isConstant() && (basex->ValueType == TypeString || basex->ValueType == TypeName))
{ {
FxExpression *x = new FxMultiNameState(static_cast<FxConstant *>(basex)->GetValue().GetString(), basex->ScriptPosition); const char *s = static_cast<FxConstant *>(basex)->GetValue().GetString();
if (*s == 0 && !ctx.FromDecorate) // DECORATE should never get here at all, but let's better be safe.
{
ScriptPosition.Message(MSG_ERROR, "State jump to empty label.");
delete this;
return nullptr;
}
FxExpression *x = new FxMultiNameState(s, basex->ScriptPosition);
x = x->Resolve(ctx); x = x->Resolve(ctx);
basex = nullptr; basex = nullptr;
delete this; delete this;
@ -1434,7 +1441,7 @@ FxExpression *FxTypeCast::Resolve(FCompileContext &ctx)
if (basex->isConstant()) if (basex->isConstant())
{ {
int i = static_cast<FxConstant *>(basex)->GetValue().GetInt(); int i = static_cast<FxConstant *>(basex)->GetValue().GetInt();
if (i < 0) if (i <= 0)
{ {
ScriptPosition.Message(MSG_ERROR, "State index must be positive"); ScriptPosition.Message(MSG_ERROR, "State index must be positive");
delete this; delete this;
@ -8087,7 +8094,7 @@ FxExpression *FxRuntimeStateIndex::Resolve(FCompileContext &ctx)
delete this; delete this;
return nullptr; return nullptr;
} }
else if (Index->isConstant() && static_cast<FxConstant *>(Index)->GetValue().GetInt() < 0) else if (Index->isConstant() && static_cast<FxConstant *>(Index)->GetValue().GetInt() <= 0)
{ {
ScriptPosition.Message(MSG_ERROR, "State index must be positive"); ScriptPosition.Message(MSG_ERROR, "State index must be positive");
delete this; delete this;