Fix from broscutamaker for "return outside function body leads to crash".

Issue #143.


git-svn-id: http://picoc.googlecode.com/svn/trunk@593 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2013-03-16 05:45:44 +00:00
parent 54cfcffa9b
commit d74c7bba38

View file

@ -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");
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