Skip to content

Commit

Permalink
Fixed crash on functions with missing return values
Browse files Browse the repository at this point in the history
  • Loading branch information
Boondorl authored and madame-rachelle committed Nov 5, 2024
1 parent 3d4dccd commit d85d04f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/common/scripting/backend/vmbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,10 +879,18 @@ void FFunctionBuildList::Build()
{
if (!item.Code->CheckReturn())
{
auto newcmpd = new FxCompoundStatement(item.Code->ScriptPosition);
newcmpd->Add(item.Code);
newcmpd->Add(new FxReturnStatement(nullptr, item.Code->ScriptPosition));
item.Code = newcmpd->Resolve(ctx);
if (ctx.ReturnProto == nullptr || !ctx.ReturnProto->ReturnTypes.Size())
{
auto newcmpd = new FxCompoundStatement(item.Code->ScriptPosition);
newcmpd->Add(item.Code);
newcmpd->Add(new FxReturnStatement(nullptr, item.Code->ScriptPosition));
item.Code = newcmpd->Resolve(ctx);
}
else
{
item.Code->ScriptPosition.Message(MSG_ERROR, "Missing return statement in %s", item.PrintableName.GetChars());
continue;
}
}

item.Proto = ctx.ReturnProto;
Expand Down

0 comments on commit d85d04f

Please sign in to comment.