mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 23:01:50 +00:00
Fixed: the game could crash while resolving expressions in some places
This commit is contained in:
parent
4a859393fe
commit
73d0ed78fe
2 changed files with 40 additions and 17 deletions
|
@ -361,16 +361,20 @@ static void FinishThingdef()
|
|||
if (sfunc == NULL)
|
||||
{
|
||||
FCompileContext ctx(ti);
|
||||
dmg->Resolve(ctx);
|
||||
VMFunctionBuilder buildit;
|
||||
buildit.Registers[REGT_POINTER].Get(1); // The self pointer
|
||||
dmg->Emit(&buildit);
|
||||
sfunc = buildit.MakeFunction();
|
||||
sfunc->NumArgs = 1;
|
||||
sfunc->Proto = NULL; ///FIXME: Need a proper prototype here
|
||||
// Save this function in case this damage value was reused
|
||||
// (which happens quite easily with inheritance).
|
||||
dmg->SetFunction(sfunc);
|
||||
dmg = static_cast<FxDamageValue *>(dmg->Resolve(ctx));
|
||||
|
||||
if (dmg != nullptr)
|
||||
{
|
||||
VMFunctionBuilder buildit;
|
||||
buildit.Registers[REGT_POINTER].Get(1); // The self pointer
|
||||
dmg->Emit(&buildit);
|
||||
sfunc = buildit.MakeFunction();
|
||||
sfunc->NumArgs = 1;
|
||||
sfunc->Proto = NULL; ///FIXME: Need a proper prototype here
|
||||
// Save this function in case this damage value was reused
|
||||
// (which happens quite easily with inheritance).
|
||||
dmg->SetFunction(sfunc);
|
||||
}
|
||||
}
|
||||
def->Damage = sfunc;
|
||||
|
||||
|
|
|
@ -191,7 +191,12 @@ static void ParseConstant (FScanner &sc, PSymbolTable *symt, PClassActor *cls)
|
|||
FxExpression *expr = ParseExpression (sc, cls, true);
|
||||
sc.MustGetToken(';');
|
||||
|
||||
if (!expr->isConstant())
|
||||
if (expr == nullptr)
|
||||
{
|
||||
sc.ScriptMessage("Error while resolving constant definition");
|
||||
FScriptPosition::ErrorCounter++;
|
||||
}
|
||||
else if (!expr->isConstant())
|
||||
{
|
||||
sc.ScriptMessage("Constant definition is not a constant");
|
||||
FScriptPosition::ErrorCounter++;
|
||||
|
@ -247,16 +252,24 @@ static void ParseEnum (FScanner &sc, PSymbolTable *symt, PClassActor *cls)
|
|||
if (sc.CheckToken('='))
|
||||
{
|
||||
FxExpression *expr = ParseExpression (sc, cls, true);
|
||||
if (!expr->isConstant())
|
||||
if (expr != nullptr)
|
||||
{
|
||||
sc.ScriptMessage("'%s' must be constant", symname.GetChars());
|
||||
FScriptPosition::ErrorCounter++;
|
||||
if (!expr->isConstant())
|
||||
{
|
||||
sc.ScriptMessage("'%s' must be constant", symname.GetChars());
|
||||
FScriptPosition::ErrorCounter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
currvalue = static_cast<FxConstant *>(expr)->GetValue().GetInt();
|
||||
}
|
||||
delete expr;
|
||||
}
|
||||
else
|
||||
{
|
||||
currvalue = static_cast<FxConstant *>(expr)->GetValue().GetInt();
|
||||
sc.ScriptMessage("Error while resolving expression of '%s'", symname.GetChars());
|
||||
FScriptPosition::ErrorCounter++;
|
||||
}
|
||||
delete expr;
|
||||
}
|
||||
PSymbolConstNumeric *sym = new PSymbolConstNumeric(symname, TypeSInt32);
|
||||
sym->Value = currvalue;
|
||||
|
@ -568,7 +581,13 @@ static void ParseUserVariable (FScanner &sc, PSymbolTable *symt, PClassActor *cl
|
|||
if (sc.CheckToken('['))
|
||||
{
|
||||
FxExpression *expr = ParseExpression(sc, cls, true);
|
||||
if (!expr->isConstant())
|
||||
if (expr == nullptr)
|
||||
{
|
||||
sc.ScriptMessage("Error while resolving array size");
|
||||
FScriptPosition::ErrorCounter++;
|
||||
maxelems = 1;
|
||||
}
|
||||
else if (!expr->isConstant())
|
||||
{
|
||||
sc.ScriptMessage("Array size must be a constant");
|
||||
FScriptPosition::ErrorCounter++;
|
||||
|
|
Loading…
Reference in a new issue