From c354000f1ce0dfdd49aa4e1839b79e189b320bbd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 6 Nov 2016 12:00:16 +0100 Subject: [PATCH] - 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. --- src/scripting/codegeneration/codegen.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index cfff4ef359..f296ac6e7d 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -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. if (basex->isConstant() && (basex->ValueType == TypeString || basex->ValueType == TypeName)) { - FxExpression *x = new FxMultiNameState(static_cast(basex)->GetValue().GetString(), basex->ScriptPosition); + const char *s = static_cast(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); basex = nullptr; delete this; @@ -1434,7 +1441,7 @@ FxExpression *FxTypeCast::Resolve(FCompileContext &ctx) if (basex->isConstant()) { int i = static_cast(basex)->GetValue().GetInt(); - if (i < 0) + if (i <= 0) { ScriptPosition.Message(MSG_ERROR, "State index must be positive"); delete this; @@ -8087,7 +8094,7 @@ FxExpression *FxRuntimeStateIndex::Resolve(FCompileContext &ctx) delete this; return nullptr; } - else if (Index->isConstant() && static_cast(Index)->GetValue().GetInt() < 0) + else if (Index->isConstant() && static_cast(Index)->GetValue().GetInt() <= 0) { ScriptPosition.Message(MSG_ERROR, "State index must be positive"); delete this;