Skip to content

Commit

Permalink
Fix from broscutamaker for "return outside function body leads to cra…
Browse files Browse the repository at this point in the history
…sh".

Issue #143.
  • Loading branch information
zik.saleeba committed Mar 16, 2013
1 parent ab1ebde commit 230e943
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,16 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
case TokenReturn:
if (Parser->Mode == RunModeRun)
{
if (Parser->pc->TopStackFrame->ReturnValue->Typ->Base != TypeVoid)
if (!Parser->pc->TopStackFrame || Parser->pc->TopStackFrame->ReturnValue->Typ->Base != TypeVoid)
{
if (!ExpressionParse(Parser, &CValue))
ProgramFail(Parser, "value required in return");

ExpressionAssign(Parser, Parser->pc->TopStackFrame->ReturnValue, CValue, TRUE, NULL, 0, FALSE);
if (!Parser->pc->TopStackFrame) /* return from top-level program? */
PlatformExit(Parser->pc, ExpressionCoerceInteger(CValue));
else
ExpressionAssign(Parser, Parser->pc->TopStackFrame->ReturnValue, CValue, TRUE, NULL, 0, FALSE);

VariableStackPop(Parser, CValue);
}
else
Expand Down

0 comments on commit 230e943

Please sign in to comment.